diff --git a/src/main/java/com/simibubi/create/content/curiosities/armor/DivingHelmetItem.java b/src/main/java/com/simibubi/create/content/curiosities/armor/DivingHelmetItem.java index a525dc198..cad10e2de 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/armor/DivingHelmetItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/armor/DivingHelmetItem.java @@ -2,6 +2,8 @@ package com.simibubi.create.content.curiosities.armor; import java.util.Locale; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.item.MultiLayeredArmorItem; @@ -30,10 +32,19 @@ public class DivingHelmetItem extends BaseArmorItem { } public static boolean isWornBy(Entity entity) { - if (!(entity instanceof LivingEntity livingEntity)) { + ItemStack stack = getWornItem(entity); + if (stack == null) { return false; } - return livingEntity.getItemBySlot(SLOT).getItem() instanceof DivingHelmetItem; + return stack.getItem() instanceof DivingHelmetItem; + } + + @Nullable + public static ItemStack getWornItem(Entity entity) { + if (!(entity instanceof LivingEntity livingEntity)) { + return null; + } + return livingEntity.getItemBySlot(SLOT); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index e40e05ddf..30404db6c 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -6,6 +6,7 @@ import java.util.List; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllFluids; +import com.simibubi.create.AllItems; import com.simibubi.create.Create; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; @@ -334,11 +335,13 @@ public class ClientEvents { return; } - if (FluidHelper.isWater(fluid) && DivingHelmetItem - .isWornBy(Minecraft.getInstance().cameraEntity)) { - event.scaleFarPlaneDistance(6.25f); - event.setCanceled(true); - return; + ItemStack divingHelmet = DivingHelmetItem.getWornItem(Minecraft.getInstance().cameraEntity); + if (divingHelmet != null) { + if (FluidHelper.isWater(fluid) || FluidHelper.isLava(fluid) && AllItems.NETHERITE_DIVING_HELMET.isIn(divingHelmet)) { + event.scaleFarPlaneDistance(6.25f); + event.setCanceled(true); + return; + } } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/EnchantmentHelperMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/EnchantmentHelperMixin.java new file mode 100644 index 000000000..d0aa55e15 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/EnchantmentHelperMixin.java @@ -0,0 +1,23 @@ +package com.simibubi.create.foundation.mixin; + +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 com.simibubi.create.content.curiosities.armor.DivingHelmetItem; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; + +@Mixin(EnchantmentHelper.class) +public class EnchantmentHelperMixin { + @Inject(method = "getItemEnchantmentLevel(Lnet/minecraft/world/item/enchantment/Enchantment;Lnet/minecraft/world/item/ItemStack;)I", at = @At("HEAD"), cancellable = true) + private static void onGetItemEnchantmentLevel(Enchantment enchantment, ItemStack stack, CallbackInfoReturnable cir) { + if (enchantment == Enchantments.AQUA_AFFINITY && stack.getItem() instanceof DivingHelmetItem) { + cir.setReturnValue(1); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/EnchantmentMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/EnchantmentMixin.java new file mode 100644 index 000000000..4c64707a8 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/EnchantmentMixin.java @@ -0,0 +1,22 @@ +package com.simibubi.create.foundation.mixin; + +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 com.simibubi.create.content.curiosities.armor.DivingHelmetItem; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.Enchantments; + +@Mixin(Enchantment.class) +public class EnchantmentMixin { + @Inject(method = "canEnchant(Lnet/minecraft/world/item/ItemStack;)Z", at = @At("HEAD"), cancellable = true) + private void onCanEnchant(ItemStack stack, CallbackInfoReturnable cir) { + if ((Object) this == Enchantments.AQUA_AFFINITY && stack.getItem() instanceof DivingHelmetItem) { + cir.setReturnValue(false); + } + } +} diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index b58d1fc36..0ef30f5a8 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -6,6 +6,8 @@ "refmap": "create.refmap.json", "mixins": [ "CustomItemUseEffectsMixin", + "EnchantmentHelperMixin", + "EnchantmentMixin", "EntityMixin", "HumanoidArmorLayerMixin", "MapItemSavedDataMixin",