diff --git a/build.gradle.kts b/build.gradle.kts index d09bb5ce..dfe28e8a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,9 +14,9 @@ val MAVEN_GROUP by extra { "uk.debb" } val LICENSE by extra { "MPL-2.0" } val MOD_VERSION by extra { "3.3.4" } -val MINECRAFT_VERSION by extra { "1.20.6" } -val MINECRAFT_VERSION_RANGE_FABRIC by extra { ">=1.20.5" } -val MINECRAFT_VERSION_RANGE_NEOFORGE by extra { "(1.20.4, 1.21)" } +val MINECRAFT_VERSION by extra { "1.21" } +val MINECRAFT_VERSION_RANGE_FABRIC by extra { ">=1.21" } +val MINECRAFT_VERSION_RANGE_NEOFORGE by extra { "[1.21,1.22)" } val H2_VERSION by extra { "2.2.224" } val ASM_VERSION by extra { "9.7" } val PARCHMENT_MC_VERSION by extra { "1.20.6" } @@ -25,9 +25,9 @@ val MIXIN_EXTRAS_VERSION by extra { "0.3.6" } val FABRIC_MIXIN_VERSION by extra { "0.14.0+mixin.0.8.6" } val FABRIC_LOADER_VERSION by extra { "0.15.11" } val FABRIC_LOADER_VERSION_RANGE by extra { ">=0.15.10" } -val MODMENU_VERSION by extra { "10.0.0-beta.1" } -val NEOFORGE_VERSION by extra { "20.6.115"} -val NEOFORGE_LOADER_VERSION_RANGE by extra { ">=20.6.0-beta" } +val MODMENU_VERSION by extra { "11.0.0-beta.1" } +val NEOFORGE_VERSION by extra { "21.0.0-beta"} +val NEOFORGE_LOADER_VERSION_RANGE by extra { ">=21.0.0-beta" } allprojects { apply(plugin = "java") diff --git a/common/src/main/java/uk/debb/vanilla_disable/config/worldgen/WorldgenConfigScreen.java b/common/src/main/java/uk/debb/vanilla_disable/config/worldgen/WorldgenConfigScreen.java index ae8a3a8e..74ff2ad0 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/config/worldgen/WorldgenConfigScreen.java +++ b/common/src/main/java/uk/debb/vanilla_disable/config/worldgen/WorldgenConfigScreen.java @@ -26,7 +26,6 @@ public class WorldgenConfigScreen extends Screen { private final CreateWorldScreen lastScreen; - private final String[] extraPlacedFeatures = {"obsidian_platform", "end_spike_cage"}; private Set biomes; private Set structures; private Set placedFeatures; @@ -59,14 +58,14 @@ protected void init() { this.biomes.forEach(biome -> WorldgenDataHandler.biomeMap.put(WorldgenDataHandler.cleanup(biome), true)); this.structures.forEach(structure -> WorldgenDataHandler.structureMap.put(WorldgenDataHandler.cleanup(structure), true)); this.placedFeatures.forEach(placedFeature -> WorldgenDataHandler.placedFeatureMap.put(WorldgenDataHandler.cleanup(placedFeature), true)); - Arrays.stream(extraPlacedFeatures).forEach(placedFeature -> WorldgenDataHandler.placedFeatureMap.put(placedFeature, true)); + WorldgenDataHandler.placedFeatureMap.put("end_spike_cage", true); worldgenConfigList.refreshEntries(); }).width(80).build(); Button disableButton = Button.builder(Component.translatable("vd.worldgen_config.disable_all"), (button) -> { this.biomes.forEach(biome -> WorldgenDataHandler.biomeMap.put(WorldgenDataHandler.cleanup(biome), false)); this.structures.forEach(structure -> WorldgenDataHandler.structureMap.put(WorldgenDataHandler.cleanup(structure), false)); this.placedFeatures.forEach(placedFeature -> WorldgenDataHandler.placedFeatureMap.put(WorldgenDataHandler.cleanup(placedFeature), false)); - Arrays.stream(extraPlacedFeatures).forEach(placedFeature -> WorldgenDataHandler.placedFeatureMap.put(placedFeature, false)); + WorldgenDataHandler.placedFeatureMap.put("end_spike_cage", false); worldgenConfigList.refreshEntries(); }).width(80).build(); Button doneButton = Button.builder(Component.translatable("vd.worldgen_config.done"), (button) -> { @@ -133,7 +132,7 @@ class WorldgenConfigCategoryEntry extends WorldgenConfigScreen.WorldgenConfigEnt case PLACED_FEATURE -> { boolean val = Collections.frequency(WorldgenDataHandler.placedFeatureMap.values(), false) < WorldgenConfigScreen.this.placedFeatures.size() / 2; WorldgenConfigScreen.this.placedFeatures.forEach(placedFeature -> WorldgenDataHandler.placedFeatureMap.put(WorldgenDataHandler.cleanup(placedFeature), !val)); - Arrays.stream(extraPlacedFeatures).forEach(placedFeature -> WorldgenDataHandler.placedFeatureMap.put(placedFeature, !val)); + WorldgenDataHandler.placedFeatureMap.put("end_spike_cage", !val); } } list.refreshEntries(); @@ -203,12 +202,9 @@ class WorldgenConfigList extends ContainerObjectSelectionList { - String adjustedPlacedFeature = "minecraft_unofficial:" + placedFeature; - if (adjustedPlacedFeature.contains(WorldgenConfigScreen.this.search)) { - this.addEntry(new WorldgenConfigToggleEntry(adjustedPlacedFeature, WorldgenConfigType.PLACED_FEATURE)); - } - }); + if ("minecraft_unofficial:end_spike_cage".contains(WorldgenConfigScreen.this.search)) { + this.addEntry(new WorldgenConfigToggleEntry("minecraft_unofficial:end_spike_cage", WorldgenConfigType.PLACED_FEATURE)); + } } public void refreshEntries() { diff --git a/common/src/main/java/uk/debb/vanilla_disable/data/command/CommandDataHandler.java b/common/src/main/java/uk/debb/vanilla_disable/data/command/CommandDataHandler.java index 5f6e7ebb..f9f5ef3a 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/data/command/CommandDataHandler.java +++ b/common/src/main/java/uk/debb/vanilla_disable/data/command/CommandDataHandler.java @@ -8,6 +8,7 @@ import it.unimi.dsi.fastutil.objects.*; import net.minecraft.commands.Commands; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.core.cauldron.CauldronInteraction; @@ -563,6 +564,10 @@ public static void populate() { put("nutrition", String.valueOf(foodProperties.nutrition())); put("saturation", String.valueOf(foodProperties.saturation())); } + if (item.equals(Items.CAKE)) { + put("nutrition", "2"); + put("saturation", "0.1"); + } if (item.equals(Items.POTION) || item.equals(Items.SPLASH_POTION) || item.equals(Items.LINGERING_POTION) || item.equals(Items.TIPPED_ARROW)) { @@ -605,7 +610,7 @@ public static void populate() { enchantmentRegistry.forEach(enchantment1 -> { if (enchantment1.equals(enchantment)) return; put("compatible_with_" + lightCleanup(Objects.requireNonNull(enchantmentRegistry.getKey(enchantment1))), - String.valueOf(enchantment.isCompatibleWith(enchantment1) && enchantment1.isCompatibleWith(enchantment))); + String.valueOf(Enchantment.areCompatible(new Holder.Direct<>(enchantment), new Holder.Direct<>(enchantment1)))); }); }})); @@ -1279,7 +1284,7 @@ private static List getBreedingItems(String row) { String columnName = resultSetMetaData.getColumnName(i); if (columnName.startsWith("can_breed_with_")) { if (resultSet.getBoolean(columnName)) { - items.add(Objects.requireNonNull(itemRegistry.get(ResourceLocation.of( + items.add(Objects.requireNonNull(itemRegistry.get(ResourceLocation.bySeparator( columnName.replace("can_breed_with_", "minecraft:"), ':')))); } } diff --git a/common/src/main/java/uk/debb/vanilla_disable/data/worldgen/WorldgenDataHandler.java b/common/src/main/java/uk/debb/vanilla_disable/data/worldgen/WorldgenDataHandler.java index fad50305..a088265e 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/data/worldgen/WorldgenDataHandler.java +++ b/common/src/main/java/uk/debb/vanilla_disable/data/worldgen/WorldgenDataHandler.java @@ -158,8 +158,7 @@ private static void createConfig(boolean write) { String clean = cleanup(placedFeature); properties.put("placed_features." + clean, placedFeatureMap.getOrDefault(clean, true)); }); - ImmutableList.of("obsidian_platform", "end_spike_cage").forEach(placedFeature -> - properties.put("placed_features." + placedFeature, placedFeatureMap.getOrDefault(placedFeature, true))); + properties.put("placed_features.end_spike_cage", placedFeatureMap.getOrDefault("end_spike_cage", true)); if (write) { try { diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinBlock.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinBlock.java new file mode 100644 index 00000000..c098ad48 --- /dev/null +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinBlock.java @@ -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; + } +} diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinEnchantment.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinEnchantment.java new file mode 100644 index 00000000..58c5d045 --- /dev/null +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinEnchantment.java @@ -0,0 +1,43 @@ +/* + * 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 com.llamalad7.mixinextras.injector.ModifyReturnValue; +import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.Enchantment; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import uk.debb.vanilla_disable.data.command.CommandDataHandler; + +@Mixin(Enchantment.class) +public abstract class MixinEnchantment { + @ModifyReturnValue(method = "canEnchant", at = @At("RETURN")) + private boolean vanillaDisable$canEnchant(boolean original, ItemStack stack) { + if (CommandDataHandler.isConnectionNull()) return original; + if (stack.getMaxDamage() == 0) return original; + String item = "can_enchant_" + CommandDataHandler.lightCleanup(CommandDataHandler.getKeyFromItemRegistry(stack.getItem())); + ResourceLocation enchantment = CommandDataHandler.enchantmentRegistry.getKey((Enchantment) (Object) this); + if (enchantment == null) return original; + return CommandDataHandler.getCachedBoolean("enchantments", enchantment.toString(), item); + } + + @ModifyReturnValue(method = "areCompatible", at = @At("RETURN")) + private static boolean vanillaDisable$areCompatible(boolean original, Holder holder, Holder holder2) { + if (CommandDataHandler.isConnectionNull()) return original; + ResourceLocation enchantmentRL = CommandDataHandler.enchantmentRegistry.getKey(holder.value()); + ResourceLocation otherEnchantmentRL = CommandDataHandler.enchantmentRegistry.getKey(holder2.value()); + if (enchantmentRL == null || otherEnchantmentRL == null) return original; + String enchantment = enchantmentRL.toString(); + String otherEnchantment = "compatible_with_" + CommandDataHandler.lightCleanup(otherEnchantmentRL); + String reversedEnchantment = enchantment.replace("minecraft:", "compatible_with_"); + String reversedOtherEnchantment = otherEnchantment.replace("compatible_with_", "minecraft:"); + return CommandDataHandler.getCachedBoolean("enchantments", enchantment, otherEnchantment) || + CommandDataHandler.getCachedBoolean("enchantments", reversedOtherEnchantment, reversedEnchantment); + } +} diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/item/MixinEnchantmentHelper.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinEnchantmentHelper.java similarity index 77% rename from common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/item/MixinEnchantmentHelper.java rename to common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinEnchantmentHelper.java index 11b8e4b0..0b952658 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/item/MixinEnchantmentHelper.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/MixinEnchantmentHelper.java @@ -4,10 +4,11 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -package uk.debb.vanilla_disable.mixin.command.enchantment.item; +package uk.debb.vanilla_disable.mixin.command.enchantment; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import net.minecraft.core.Holder; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; @@ -19,14 +20,14 @@ @Mixin(EnchantmentHelper.class) public abstract class MixinEnchantmentHelper { @ModifyReturnValue(method = "getItemEnchantmentLevel", at = @At("RETURN")) - private static int vanillaDisable$getItemEnchantmentLevel(int original, Enchantment enchantment, ItemStack stack) { - String item = "can_enchant_" + CommandDataHandler.lightCleanup(CommandDataHandler.getKeyFromItemRegistry(stack.getItem())); - if (!CommandDataHandler.getCachedBoolean("enchantments", CommandDataHandler.getKeyFromEnchantmentRegistry(enchantment), item)) { - ItemEnchantments itemEnchantments = stack.getEnchantments(); + private static int vanillaDisable$getItemEnchantmentLevel(int original, Holder holder, ItemStack itemStack) { + String item = "can_enchant_" + CommandDataHandler.lightCleanup(CommandDataHandler.getKeyFromItemRegistry(itemStack.getItem())); + if (!CommandDataHandler.getCachedBoolean("enchantments", CommandDataHandler.getKeyFromEnchantmentRegistry(holder.value()), item)) { + 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(stack, itemEnchantments); + EnchantmentHelper.setEnchantments(itemStack, itemEnchantments); return 0; } return original; diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/compatibility/MixinEnchantment.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/compatibility/MixinEnchantment.java deleted file mode 100644 index 0b8f292f..00000000 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/compatibility/MixinEnchantment.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.compatibility; - -import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import net.minecraft.world.item.enchantment.Enchantment; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import uk.debb.vanilla_disable.data.command.CommandDataHandler; - -@Mixin(Enchantment.class) -public abstract class MixinEnchantment { - @ModifyReturnValue(method = "isCompatibleWith", at = @At("RETURN")) - private boolean vanillaDisable$isCompatibleWith(boolean original, Enchantment other) { - if (CommandDataHandler.isConnectionNull()) return original; - String enchantment = CommandDataHandler.getKeyFromEnchantmentRegistry((Enchantment) (Object) this); - String otherEnchantment = "compatible_with_" + CommandDataHandler.lightCleanup(CommandDataHandler.getKeyFromEnchantmentRegistry(other)); - String reversedEnchantment = enchantment.replace("minecraft:", "compatible_with_"); - String reversedOtherEnchantment = otherEnchantment.replace("compatible_with_", "minecraft:"); - return CommandDataHandler.getCachedBoolean("enchantments", enchantment, otherEnchantment) || - CommandDataHandler.getCachedBoolean("enchantments", reversedOtherEnchantment, reversedEnchantment); - } -} diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/item/MixinEnchantment.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/item/MixinEnchantment.java deleted file mode 100644 index fd8a7901..00000000 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/enchantment/item/MixinEnchantment.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.item; - -import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import uk.debb.vanilla_disable.data.command.CommandDataHandler; - -@Mixin(Enchantment.class) -public abstract class MixinEnchantment { - @ModifyReturnValue(method = "canEnchant", at = @At("RETURN")) - private boolean vanillaDisable$canEnchant(boolean original, ItemStack stack) { - if (CommandDataHandler.isConnectionNull()) return original; - if (stack.getMaxDamage() == 0) return original; - String item = "can_enchant_" + CommandDataHandler.lightCleanup(CommandDataHandler.getKeyFromItemRegistry(stack.getItem())); - return CommandDataHandler.getCachedBoolean("enchantments", CommandDataHandler.getKeyFromEnchantmentRegistry((Enchantment) (Object) this), item); - } -} diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/other/MixinPainting.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/other/MixinPainting.java index 4df09f06..f00adb45 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/other/MixinPainting.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/other/MixinPainting.java @@ -8,13 +8,10 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.core.Holder; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.decoration.Painting; import net.minecraft.world.entity.decoration.PaintingVariant; -import org.spongepowered.asm.mixin.Final; +import net.minecraft.world.entity.decoration.PaintingVariants; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import uk.debb.vanilla_disable.data.command.CommandDataHandler; @@ -22,15 +19,10 @@ @Mixin(Painting.class) public abstract class MixinPainting { - @Shadow - @Final - private static ResourceKey DEFAULT_VARIANT; - @ModifyReturnValue(method = "getVariant()Lnet/minecraft/core/Holder;", at = @At("RETURN")) private Holder vanillaDisable$getVariant(Holder original) { - if (!CommandDataHandler.getCachedBoolean("entities", "minecraft:painting", - CommandDataHandler.lightCleanup(Objects.requireNonNull(CommandDataHandler.paintingVariantRegistry.getKey(original.value()))) + "_painting")) { - return BuiltInRegistries.PAINTING_VARIANT.getHolderOrThrow(DEFAULT_VARIANT); + if (!CommandDataHandler.getCachedBoolean("entities", "minecraft:painting", CommandDataHandler.lightCleanup(original.value().assetId()) + "_painting")) { + return new Holder.Direct<>(Objects.requireNonNull(CommandDataHandler.paintingVariantRegistry.get(PaintingVariants.KEBAB))); } return original; } diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/other/MixinPlayer.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/other/MixinPlayer.java index 9e841f9b..08ab61ab 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/other/MixinPlayer.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/other/MixinPlayer.java @@ -7,13 +7,15 @@ package uk.debb.vanilla_disable.mixin.command.entity.other; import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import net.minecraft.core.component.DataComponents; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.monster.Creeper; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.item.enchantment.ItemEnchantments; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -33,7 +35,9 @@ public abstract class MixinPlayer { @Inject(method = "attack", at = @At("RETURN")) private void vanillaDisable$attack(Entity target, CallbackInfo ci) { - if (target instanceof Creeper creeper && EnchantmentHelper.getFireAspect((Player) (Object) this) > 0 && + boolean hasFireAspect = ((Player) (Object) this).getMainHandItem().getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY) + .keySet().stream().anyMatch(enchantment -> enchantment.is(Enchantments.FIRE_ASPECT.location())); + if (target instanceof Creeper creeper && hasFireAspect && CommandDataHandler.getCachedBoolean("entities", "minecraft:creeper", "can_be_lit_by_fire_aspect")) { creeper.ignite(); } diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/player/hunger/MixinCakeBlock.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/player/hunger/MixinCakeBlock.java new file mode 100644 index 00000000..b3e5014b --- /dev/null +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/player/hunger/MixinCakeBlock.java @@ -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 cir) { + if (CommandDataHandler.getCachedBoolean("entities", "minecraft:player", "beta_hunger")) { + int nutrition = CommandDataHandler.getCachedInt("items", "minecraft:cake", "nutrition"); + player.setHealth(player.getHealth() + nutrition); + } + } +} diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/player/hunger/MixinPlayer.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/player/hunger/MixinPlayer.java index a297a5d8..41b67f22 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/player/hunger/MixinPlayer.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/entity/player/hunger/MixinPlayer.java @@ -7,9 +7,9 @@ package uk.debb.vanilla_disable.mixin.command.entity.player.hunger; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import net.minecraft.core.component.DataComponents; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; @@ -21,9 +21,9 @@ @Mixin(Player.class) public abstract class MixinPlayer { @Inject(method = "eat", at = @At("HEAD")) - private void vanillaDisable$eat(Level level, ItemStack food, CallbackInfoReturnable cir) { + private void vanillaDisable$eat(Level level, ItemStack food, FoodProperties foodProperties, CallbackInfoReturnable cir) { LivingEntity livingEntity = (LivingEntity) (Object) this; - if (food.get(DataComponents.FOOD) != null && CommandDataHandler.getCachedBoolean("entities", "minecraft:player", "beta_hunger")) { + if (foodProperties != null && CommandDataHandler.getCachedBoolean("entities", "minecraft:player", "beta_hunger")) { int nutrition = CommandDataHandler.getCachedInt("items", CommandDataHandler.getKeyFromItemRegistry(food.getItem()), "nutrition"); livingEntity.setHealth(livingEntity.getHealth() + nutrition); } diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/food/MixinCakeBlock.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/food/MixinCakeBlock.java new file mode 100644 index 00000000..e41acd00 --- /dev/null +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/food/MixinCakeBlock.java @@ -0,0 +1,31 @@ +/* + * 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.item.food; + +import net.minecraft.world.level.block.CakeBlock; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; +import uk.debb.vanilla_disable.data.command.CommandDataHandler; + +@Mixin(CakeBlock.class) +public abstract class MixinCakeBlock { + @ModifyArgs( + method = "eat", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/food/FoodData;eat(IF)V" + ) + ) + private static void vanillaDisable$eat(Args args) { + int nutrition = CommandDataHandler.getCachedInt("items", "minecraft:cake", "nutrition"); + float saturation = (float) CommandDataHandler.getCachedDouble("items", "minecraft:cake", "saturation"); + args.set(0, nutrition); + args.set(1, saturation); + } +} diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/food/MixinPlayer.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/food/MixinPlayer.java new file mode 100644 index 00000000..0a38b43b --- /dev/null +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/food/MixinPlayer.java @@ -0,0 +1,44 @@ +/* + * 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.item.food; + +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.food.FoodData; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +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(Player.class) +public abstract class MixinPlayer { + @Shadow public abstract FoodData getFoodData(); + + @Inject(method = "eat", at = @At("HEAD")) + private void vanillaDisable$eat(Level level, ItemStack itemStack, FoodProperties foodProperties, CallbackInfoReturnable cir) { + String name = CommandDataHandler.getKeyFromItemRegistry(itemStack.getItem()); + int nutrition = CommandDataHandler.getCachedInt("items", name, "nutrition"); + float saturation = (float) CommandDataHandler.getCachedDouble("items", name, "saturation"); + this.getFoodData().eat(nutrition, saturation); + } + + @WrapWithCondition( + method = "eat", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/food/FoodData;eat(Lnet/minecraft/world/food/FoodProperties;)V" + ) + ) + private boolean vanillaDisable$eat1(FoodData instance, FoodProperties foodProperties) { + return false; + } +} diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/other/MixinFoodData.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/other/MixinFoodData.java deleted file mode 100644 index 42ec8034..00000000 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/command/item/other/MixinFoodData.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.item.other; - -import net.minecraft.core.component.DataComponents; -import net.minecraft.world.food.FoodData; -import net.minecraft.world.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import uk.debb.vanilla_disable.data.command.CommandDataHandler; - -@Mixin(FoodData.class) -public abstract class MixinFoodData { - @Shadow - public abstract void eat(int i, float f); - - @Inject(method = "eat(Lnet/minecraft/world/item/ItemStack;)V", at = @At("HEAD"), cancellable = true) - private void vanillaDisable$eat(ItemStack stack, CallbackInfo ci) { - if (stack.get(DataComponents.FOOD) != null) { - String name = CommandDataHandler.getKeyFromItemRegistry(stack.getItem()); - int nutrition = CommandDataHandler.getCachedInt("items", name, "nutrition"); - float saturation = (float) CommandDataHandler.getCachedDouble("items", name, "saturation"); - this.eat(nutrition, saturation); - } - ci.cancel(); - } -} diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/feature/MixinServerLevel.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/feature/MixinEndPlatformFeature.java similarity index 51% rename from common/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/feature/MixinServerLevel.java rename to common/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/feature/MixinEndPlatformFeature.java index 8cbd862f..06b13dac 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/feature/MixinServerLevel.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/feature/MixinEndPlatformFeature.java @@ -6,18 +6,20 @@ package uk.debb.vanilla_disable.mixin.worldgen.feature; -import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.level.levelgen.feature.EndPlatformFeature; 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.CallbackInfo; import uk.debb.vanilla_disable.data.worldgen.WorldgenDataHandler; -@Mixin(ServerLevel.class) -public abstract class MixinServerLevel { - @Inject(method = "makeObsidianPlatform", at = @At("HEAD"), cancellable = true) - private static void vanillaDisable$makeObsidianPlatform(CallbackInfo ci) { - if (!WorldgenDataHandler.get("placed_features", "obsidian_platform")) { +@Mixin(EndPlatformFeature.class) +public abstract class MixinEndPlatformFeature { + @Inject(method = "createEndPlatform", at = @At("HEAD"), cancellable = true) + private static void vanillaDisable$createEndPlatform(ServerLevelAccessor serverLevelAccessor, BlockPos blockPos, boolean bl, CallbackInfo ci) { + if (!WorldgenDataHandler.get("placed_features", "minecraft:end_platform")) { ci.cancel(); } } diff --git a/common/src/main/resources/vanilla_disable.mixins.json b/common/src/main/resources/vanilla_disable.mixins.json index e85b56f4..a6d7fe48 100644 --- a/common/src/main/resources/vanilla_disable.mixins.json +++ b/common/src/main/resources/vanilla_disable.mixins.json @@ -43,9 +43,9 @@ "command.block.redstone_timings.MixinObserverBlock", "command.block.redstone_timings.MixinRepeaterBlock", "command.command.MixinCommands", - "command.enchantment.compatibility.MixinEnchantment", - "command.enchantment.item.MixinEnchantment", - "command.enchantment.item.MixinEnchantmentHelper", + "command.enchantment.MixinBlock", + "command.enchantment.MixinEnchantment", + "command.enchantment.MixinEnchantmentHelper", "command.entity.breeding.MixinBreedGoal", "command.entity.breeding.MixinTemptGoal", "command.entity.breeding.MixinVillager", @@ -74,6 +74,7 @@ "command.entity.other.MixinZombieVillager", "command.entity.player.MixinAbilities", "command.entity.player.MixinEntity", + "command.entity.player.hunger.MixinCakeBlock", "command.entity.player.hunger.MixinFoodData", "command.entity.player.hunger.MixinItem", "command.entity.player.hunger.MixinPlayer", @@ -93,13 +94,14 @@ "command.entity.trading.MixinVillager", "command.item.creative_breaking.MixinItem", "command.item.creative_breaking.MixinSwordItem", + "command.item.food.MixinCakeBlock", + "command.item.food.MixinPlayer", "command.item.function.MixinItemStack", "command.item.function.MixinLivingEntity", "command.item.function.MixinSpectralArrow", "command.item.other.MixinAbstractCauldronBlock", "command.item.other.MixinAbstractFurnaceBlockEntity", "command.item.other.MixinDispenserBlock", - "command.item.other.MixinFoodData", "command.item.other.MixinGiveCommand", "command.item.other.MixinItemStack", "command.item.potion.MixinArrow", @@ -126,8 +128,8 @@ "worldgen.biome.MixinBiomeManager", "worldgen.biome.MixinBiomeSource", "worldgen.feature.MixinBiomeGenerationSettings", + "worldgen.feature.MixinEndPlatformFeature", "worldgen.feature.MixinEndSpike", - "worldgen.feature.MixinServerLevel", "worldgen.structure.MixinStructureCheck", "worldgen.structure.MixinStructureManager" ],