generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some crashes and other issues, add nutrition/saturation control a…
…nd beta hunger for cakes
- Loading branch information
1 parent
a229d68
commit 5cd3521
Showing
7 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package uk.debb.vanilla_disable.mixin.command.enchantment; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.enchantment.EnchantmentHelper; | ||
import net.minecraft.world.item.enchantment.ItemEnchantments; | ||
import net.minecraft.world.level.block.Block; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import uk.debb.vanilla_disable.data.command.CommandDataHandler; | ||
|
||
@Mixin(Block.class) | ||
public abstract class MixinBlock { | ||
@ModifyArg( | ||
method = "getDrops(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)Ljava/util/List;", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/level/storage/loot/LootParams$Builder;withParameter(Lnet/minecraft/world/level/storage/loot/parameters/LootContextParam;Ljava/lang/Object;)Lnet/minecraft/world/level/storage/loot/LootParams$Builder;", | ||
ordinal = 1 | ||
), | ||
index = 1 | ||
) | ||
private static Object vanillaDisable$getDrops(Object value) { | ||
if (value instanceof ItemStack itemStack) { | ||
String item = "can_enchant_" + CommandDataHandler.lightCleanup(CommandDataHandler.getKeyFromItemRegistry(itemStack.getItem())); | ||
ItemEnchantments itemEnchantments = itemStack.getEnchantments(); | ||
itemEnchantments.enchantments = itemEnchantments.enchantments.object2IntEntrySet().stream() | ||
.filter(e -> CommandDataHandler.getCachedBoolean("enchantments", CommandDataHandler.getKeyFromEnchantmentRegistry(e.getKey().value()), item)) | ||
.collect(Object2IntOpenHashMap::new, (m, e) -> m.put(e.getKey(), e.getIntValue()), Object2IntOpenHashMap::putAll); | ||
EnchantmentHelper.setEnchantments(itemStack, itemEnchantments); | ||
return itemStack; | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../main/java/uk/debb/vanilla_disable/mixin/command/entity/player/hunger/MixinCakeBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package uk.debb.vanilla_disable.mixin.command.entity.player.hunger; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.LevelAccessor; | ||
import net.minecraft.world.level.block.CakeBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import uk.debb.vanilla_disable.data.command.CommandDataHandler; | ||
|
||
@Mixin(CakeBlock.class) | ||
public abstract class MixinCakeBlock { | ||
@Inject( | ||
method = "eat", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/food/FoodData;eat(IF)V" | ||
) | ||
) | ||
private static void vanillaDisable$eat(LevelAccessor level, BlockPos pos, BlockState state, Player player, CallbackInfoReturnable<InteractionResult> cir) { | ||
if (CommandDataHandler.getCachedBoolean("entities", "minecraft:player", "beta_hunger")) { | ||
int nutrition = CommandDataHandler.getCachedInt("items", "minecraft:cake", "nutrition"); | ||
player.setHealth(player.getHealth() + nutrition); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters