From 29e3d101f1699d74d3328f210683a37e3f4876c7 Mon Sep 17 00:00:00 2001 From: Louis Caron Date: Tue, 3 Sep 2024 19:21:26 -0400 Subject: [PATCH 1/3] separation of AncientWillContainer and TerrasteelHelmItem --- .../integration/rei/BotaniaREIPlugin.java | 3 +- .../fabric/mixin/PlayerFabricMixin.java | 3 +- .../botania/forge/ForgeCommonInitializer.java | 10 +- .../api/item/AncientWillContainer.java | 96 ++++++++++++++++++- .../integration/emi/AncientWillEmiRecipe.java | 2 +- .../crafting/AncientWillRecipeWrapper.java | 2 +- .../render/entity/TerrasteelHelmetLayer.java | 3 +- .../crafting/recipe/AncientWillRecipe.java | 5 +- .../armor/terrasteel/TerrasteelHelmItem.java | 85 +--------------- .../vazkii/botania/mixin/PlayerMixin.java | 3 +- 10 files changed, 114 insertions(+), 98 deletions(-) diff --git a/Fabric/src/main/java/vazkii/botania/fabric/integration/rei/BotaniaREIPlugin.java b/Fabric/src/main/java/vazkii/botania/fabric/integration/rei/BotaniaREIPlugin.java index ee1cc25128..5f27003cf0 100644 --- a/Fabric/src/main/java/vazkii/botania/fabric/integration/rei/BotaniaREIPlugin.java +++ b/Fabric/src/main/java/vazkii/botania/fabric/integration/rei/BotaniaREIPlugin.java @@ -151,14 +151,13 @@ void registerAncientWillRecipeWrapper(DisplayRegistry helper) { ImmutableList.Builder input = ImmutableList.builder(); ImmutableList.Builder> output = ImmutableList.builder(); Set wills = ImmutableSet.of(new ItemStack(BotaniaItems.ancientWillAhrim), new ItemStack(BotaniaItems.ancientWillDharok), new ItemStack(BotaniaItems.ancientWillGuthan), new ItemStack(BotaniaItems.ancientWillKaril), new ItemStack(BotaniaItems.ancientWillTorag), new ItemStack(BotaniaItems.ancientWillVerac)); - AncientWillContainer container = (AncientWillContainer) BotaniaItems.terrasteelHelm; ItemStack helmet = new ItemStack(BotaniaItems.terrasteelHelm); input.add(EntryIngredients.of(helmet)); input.add(EntryIngredients.ofItemStacks(wills)); for (ItemStack will : wills) { ItemStack copy = helmet.copy(); - container.addAncientWill(copy, ((AncientWillItem) will.getItem()).type); + AncientWillContainer.addAncientWill(copy, ((AncientWillItem) will.getItem()).type); output.add(EntryStacks.of(copy)); } helper.add(new DefaultCustomDisplay(null, input.build(), Collections.singletonList(EntryIngredient.of(output.build())))); diff --git a/Fabric/src/main/java/vazkii/botania/fabric/mixin/PlayerFabricMixin.java b/Fabric/src/main/java/vazkii/botania/fabric/mixin/PlayerFabricMixin.java index bd1a61450e..cbdb53aa90 100644 --- a/Fabric/src/main/java/vazkii/botania/fabric/mixin/PlayerFabricMixin.java +++ b/Fabric/src/main/java/vazkii/botania/fabric/mixin/PlayerFabricMixin.java @@ -33,6 +33,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; +import vazkii.botania.api.item.AncientWillContainer; import vazkii.botania.common.PlayerAccess; import vazkii.botania.common.handler.EquipmentHandler; import vazkii.botania.common.handler.PixieHandler; @@ -123,7 +124,7 @@ private float cushionFall(float originalDist) { private float onCritMul(float f, Entity target) { if (target instanceof LivingEntity living) { ((PlayerAccess) this).botania$setCritTarget(living); - return f * TerrasteelHelmItem.getCritDamageMult((Player) (Object) this); + return f * AncientWillContainer.getCritDamageMult((Player) (Object) this); } return f; } diff --git a/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java b/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java index 283e0ea270..0f02658292 100644 --- a/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java +++ b/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java @@ -20,6 +20,7 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.monster.EnderMan; @@ -65,10 +66,7 @@ import vazkii.botania.api.BotaniaRegistries; import vazkii.botania.api.block.HornHarvestable; import vazkii.botania.api.block.Wandable; -import vazkii.botania.api.item.AvatarWieldable; -import vazkii.botania.api.item.BlockProvider; -import vazkii.botania.api.item.CoordBoundItem; -import vazkii.botania.api.item.Relic; +import vazkii.botania.api.item.*; import vazkii.botania.api.mana.*; import vazkii.botania.api.mana.spark.SparkAttachable; import vazkii.botania.client.fx.BotaniaParticles; @@ -446,11 +444,11 @@ private void registerEvents() { if (e.getEntity().level().isClientSide || result == Event.Result.DENY || result == Event.Result.DEFAULT && !e.isVanillaCritical() - || !TerrasteelHelmItem.hasTerraArmorSet(e.getEntity()) + || !(e.getEntity().getItemBySlot(EquipmentSlot.HEAD).getItem() instanceof AncientWillContainer awc && awc.hasFullArmorSet(e.getEntity())) || !(e.getTarget() instanceof LivingEntity target)) { return; } - e.setDamageModifier(e.getDamageModifier() * TerrasteelHelmItem.getCritDamageMult(e.getEntity())); + e.setDamageModifier(e.getDamageModifier() * AncientWillContainer.getCritDamageMult(e.getEntity())); ((PlayerAccess) e.getEntity()).botania$setCritTarget(target); }); diff --git a/Xplat/src/main/java/vazkii/botania/api/item/AncientWillContainer.java b/Xplat/src/main/java/vazkii/botania/api/item/AncientWillContainer.java index 68e4b7d783..63b4273590 100644 --- a/Xplat/src/main/java/vazkii/botania/api/item/AncientWillContainer.java +++ b/Xplat/src/main/java/vazkii/botania/api/item/AncientWillContainer.java @@ -8,13 +8,32 @@ */ package vazkii.botania.api.item; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import vazkii.botania.api.mana.ManaItemHandler; +import vazkii.botania.common.BotaniaDamageTypes; +import vazkii.botania.common.helper.ItemNBTHelper; +import vazkii.botania.common.item.equipment.armor.terrasteel.TerrasteelHelmItem; + +import java.util.List; +import java.util.Locale; /** * An item that implements this can have Ancient Wills * crafted onto it. */ public interface AncientWillContainer { + + String TAG_ANCIENT_WILL = "AncientWill"; enum AncientWillType { AHRIM, DHAROK, @@ -24,8 +43,81 @@ enum AncientWillType { KARIL } - void addAncientWill(ItemStack stack, AncientWillType will); + static void addAncientWill(ItemStack stack, AncientWillType will) { + ItemNBTHelper.setBoolean(stack, TAG_ANCIENT_WILL + "_" + will.name().toLowerCase(Locale.ROOT), true); + } + + static boolean hasAncientWill(ItemStack stack, AncientWillType will) { + return ItemNBTHelper.getBoolean(stack, TAG_ANCIENT_WILL + "_" + will.name().toLowerCase(Locale.ROOT), false); + } + + static float getCritDamageMult(Player player) { + ItemStack stack = player.getItemBySlot(EquipmentSlot.HEAD); + if (stack.getItem() instanceof AncientWillContainer awc && awc.hasFullArmorSet(player)) { + if (!stack.isEmpty() && AncientWillContainer.hasAncientWill(stack, AncientWillType.DHAROK)) { + return 1.0F + (1.0F - player.getHealth() / player.getMaxHealth()) * 0.5F; + } + } + + return 1.0F; + } + + static boolean hasAnyWill(ItemStack stack) { + for (AncientWillType type : AncientWillType.values()) { + if (AncientWillContainer.hasAncientWill(stack, type)) { + return true; + } + } + + return false; + } - boolean hasAncientWill(ItemStack stack, AncientWillType will); + static DamageSource onEntityAttacked(DamageSource source, float amount, Player player, LivingEntity entity) { + ItemStack stack = player.getItemBySlot(EquipmentSlot.HEAD); + if (stack.getItem() instanceof AncientWillContainer awc && awc.hasFullArmorSet(player)) { + if (AncientWillContainer.hasAncientWill(stack, AncientWillType.AHRIM)) { + entity.addEffect(new MobEffectInstance(MobEffects.WEAKNESS, 20, 1)); + } + + if (AncientWillContainer.hasAncientWill(stack, AncientWillType.GUTHAN)) { + player.heal(amount * 0.25F); + } + + if (AncientWillContainer.hasAncientWill(stack, AncientWillType.TORAG)) { + entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 60, 1)); + } + + if (AncientWillContainer.hasAncientWill(stack, AncientWillType.VERAC)) { + source = BotaniaDamageTypes.Sources.playerAttackArmorPiercing(player.level().registryAccess(), player); + } + + if (AncientWillContainer.hasAncientWill(stack, AncientWillType.KARIL)) { + entity.addEffect(new MobEffectInstance(MobEffects.WITHER, 60, 1)); + } + } + + return source; + } + + static void addAncientWillDescription(ItemStack stack, List list){ + for (AncientWillType type : AncientWillType.values()) { + if (hasAncientWill(stack, type)) { + list.add(Component.translatable("botania.armorset.will_" + type.name().toLowerCase(Locale.ROOT) + ".desc").withStyle(ChatFormatting.GRAY)); + } + } + } + + static void ancientWillInventoryTick(ItemStack stack, Level world, Entity entity){ + if (!world.isClientSide && entity instanceof Player player && player.getInventory().armor.contains(stack) && stack.getItem() instanceof AncientWillContainer awc && awc.hasFullArmorSet(player)) { + int food = player.getFoodData().getFoodLevel(); + if (food > 0 && food < 18 && player.isHurt() && player.tickCount % 80 == 0) { + player.heal(1F); + } + if (player.tickCount % 10 == 0) { + ManaItemHandler.instance().dispatchManaExact(stack, player, 10, true); + } + } + } + boolean hasFullArmorSet(Player player); } diff --git a/Xplat/src/main/java/vazkii/botania/client/integration/emi/AncientWillEmiRecipe.java b/Xplat/src/main/java/vazkii/botania/client/integration/emi/AncientWillEmiRecipe.java index 72f0f4e8a9..34c970278c 100644 --- a/Xplat/src/main/java/vazkii/botania/client/integration/emi/AncientWillEmiRecipe.java +++ b/Xplat/src/main/java/vazkii/botania/client/integration/emi/AncientWillEmiRecipe.java @@ -39,7 +39,7 @@ public SlotWidget getOutputWidget(int x, int y) { return new GeneratedSlotWidget(r -> { ItemStack stack = container.getItemStack().copy(); ItemStack will = wills.get(r.nextInt(wills.size())).getItemStack().copy(); - ((AncientWillContainer) stack.getItem()).addAncientWill(stack, ((AncientWillItem) will.getItem()).type); + AncientWillContainer.addAncientWill(stack, ((AncientWillItem) will.getItem()).type); return EmiStack.of(stack); }, unique, x, y); } diff --git a/Xplat/src/main/java/vazkii/botania/client/integration/jei/crafting/AncientWillRecipeWrapper.java b/Xplat/src/main/java/vazkii/botania/client/integration/jei/crafting/AncientWillRecipeWrapper.java index df30c3f1c4..b1214563c4 100644 --- a/Xplat/src/main/java/vazkii/botania/client/integration/jei/crafting/AncientWillRecipeWrapper.java +++ b/Xplat/src/main/java/vazkii/botania/client/integration/jei/crafting/AncientWillRecipeWrapper.java @@ -62,7 +62,7 @@ public void setRecipe(@NotNull IRecipeLayoutBuilder builder, @NotNull ICraftingG var outputStacks = new ArrayList(); for (var will : !foci.isEmpty() ? foci : willStacks) { var stack = new ItemStack(BotaniaItems.terrasteelHelm); - ((AncientWillContainer) stack.getItem()).addAncientWill(stack, ((AncientWillItem) will.getItem()).type); + AncientWillContainer.addAncientWill(stack, ((AncientWillItem) will.getItem()).type); outputStacks.add(stack); } diff --git a/Xplat/src/main/java/vazkii/botania/client/render/entity/TerrasteelHelmetLayer.java b/Xplat/src/main/java/vazkii/botania/client/render/entity/TerrasteelHelmetLayer.java index 81da62ea01..8df2b51b00 100644 --- a/Xplat/src/main/java/vazkii/botania/client/render/entity/TerrasteelHelmetLayer.java +++ b/Xplat/src/main/java/vazkii/botania/client/render/entity/TerrasteelHelmetLayer.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; +import vazkii.botania.api.item.AncientWillContainer; import vazkii.botania.client.core.handler.MiscellaneousModels; import vazkii.botania.common.item.equipment.armor.terrasteel.TerrasteelHelmItem; @@ -37,7 +38,7 @@ public TerrasteelHelmetLayer(RenderLayerParent 0 && food < 18 && player.isHurt() && player.tickCount % 80 == 0) { - player.heal(1F); - } - if (player.tickCount % 10 == 0) { - ManaItemHandler.instance().dispatchManaExact(stack, player, 10, true); - } - } + AncientWillContainer.ancientWillInventoryTick(stack, world, entity); } @Override @@ -61,77 +49,14 @@ public float getDiscount(ItemStack stack, int slot, Player player, @Nullable Ite return hasArmorSet(player) ? 0.2F : 0F; } - @Override - public void addAncientWill(ItemStack stack, AncientWillType will) { - ItemNBTHelper.setBoolean(stack, TAG_ANCIENT_WILL + "_" + will.name().toLowerCase(Locale.ROOT), true); - } - - @Override - public boolean hasAncientWill(ItemStack stack, AncientWillType will) { - return hasAncientWill_(stack, will); - } - - private static boolean hasAncientWill_(ItemStack stack, AncientWillType will) { - return ItemNBTHelper.getBoolean(stack, TAG_ANCIENT_WILL + "_" + will.name().toLowerCase(Locale.ROOT), false); - } - @Override public void addArmorSetDescription(ItemStack stack, List list) { super.addArmorSetDescription(stack, list); - for (AncientWillType type : AncientWillType.values()) { - if (hasAncientWill(stack, type)) { - list.add(Component.translatable("botania.armorset.will_" + type.name().toLowerCase(Locale.ROOT) + ".desc").withStyle(ChatFormatting.GRAY)); - } - } + AncientWillContainer.addAncientWillDescription(stack, list); } - public static boolean hasAnyWill(ItemStack stack) { - for (AncientWillType type : AncientWillType.values()) { - if (hasAncientWill_(stack, type)) { - return true; - } - } - - return false; - } - - public static boolean hasTerraArmorSet(Player player) { - return ((TerrasteelHelmItem) BotaniaItems.terrasteelHelm).hasArmorSet(player); - } - - public static float getCritDamageMult(Player player) { - if (hasTerraArmorSet(player)) { - ItemStack stack = player.getItemBySlot(EquipmentSlot.HEAD); - if (!stack.isEmpty() && stack.getItem() instanceof TerrasteelHelmItem - && hasAncientWill_(stack, AncientWillType.DHAROK)) { - return 1F + (1F - player.getHealth() / player.getMaxHealth()) * 0.5F; - } - } - return 1.0F; - } - - public static DamageSource onEntityAttacked(DamageSource source, float amount, Player player, LivingEntity entity) { - if (hasTerraArmorSet(player)) { - ItemStack stack = player.getItemBySlot(EquipmentSlot.HEAD); - if (!stack.isEmpty() && stack.getItem() instanceof TerrasteelHelmItem) { - if (hasAncientWill_(stack, AncientWillType.AHRIM)) { - entity.addEffect(new MobEffectInstance(MobEffects.WEAKNESS, 20, 1)); - } - if (hasAncientWill_(stack, AncientWillType.GUTHAN)) { - player.heal(amount * 0.25F); - } - if (hasAncientWill_(stack, AncientWillType.TORAG)) { - entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 60, 1)); - } - if (hasAncientWill_(stack, AncientWillType.VERAC)) { - source = BotaniaDamageTypes.Sources.playerAttackArmorPiercing(player.level().registryAccess(), player); - } - if (hasAncientWill_(stack, AncientWillType.KARIL)) { - entity.addEffect(new MobEffectInstance(MobEffects.WITHER, 60, 1)); - } - } - } - return source; + @Override + public boolean hasFullArmorSet(Player player) { + return hasArmorSet(player); } - } diff --git a/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java b/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java index 093791a5ff..ae06d1b2bd 100644 --- a/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java +++ b/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java @@ -18,6 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import vazkii.botania.api.item.AncientWillContainer; import vazkii.botania.common.BotaniaStats; import vazkii.botania.common.PlayerAccess; import vazkii.botania.common.entity.BotaniaEntities; @@ -61,7 +62,7 @@ private void trackLuminizerTravel(double dx, double dy, double dz, CallbackInfo ) private DamageSource onDamageTarget(DamageSource source, float amount) { if (this.terraWillCritTarget != null) { - DamageSource newSource = TerrasteelHelmItem.onEntityAttacked(source, amount, (Player) (Object) this, terraWillCritTarget); + DamageSource newSource = AncientWillContainer.onEntityAttacked(source, amount, (Player) (Object) this, terraWillCritTarget); this.terraWillCritTarget = null; return newSource; } From 0f1e3a2bfb17d313b1f6ec590d614b538b21f03e Mon Sep 17 00:00:00 2001 From: Louis Caron Date: Sat, 2 Nov 2024 00:54:50 -0400 Subject: [PATCH 2/3] fix merge 1.21.1 --- .../java/vazkii/botania/mixin/PlayerMixin.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java b/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java index 3fa981850d..4ab9a92cee 100644 --- a/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java +++ b/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java @@ -33,22 +33,6 @@ protected PlayerMixin(EntityType type, Level level) { @Unique private LivingEntity terraWillCritTarget; - @Shadow - public abstract void awardStat(ResourceLocation stat, int i); - - /** - * Updates the distance by luminizer stat - */ - @Inject( - at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/entity/player/Player;getVehicle()Lnet/minecraft/world/entity/Entity;"), - method = "checkRidingStatistics", locals = LocalCapture.CAPTURE_FAILSOFT - ) - private void trackLuminizerTravel(double dx, double dy, double dz, CallbackInfo ci, int cm, Entity mount) { - if (mount.getType() == BotaniaEntities.PLAYER_MOVER) { - awardStat(BotaniaStats.LUMINIZER_ONE_CM, cm); - } - } - @Override public void botania$setCritTarget(LivingEntity entity) { this.terraWillCritTarget = entity; From e64c5d1bd948dad62d72c58e6120f8226a6fc0b9 Mon Sep 17 00:00:00 2001 From: Louis Caron Date: Sat, 2 Nov 2024 00:56:20 -0400 Subject: [PATCH 3/3] removing useless imports --- Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java b/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java index 4ab9a92cee..5b310b795b 100644 --- a/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java +++ b/Xplat/src/main/java/vazkii/botania/mixin/PlayerMixin.java @@ -1,27 +1,21 @@ package vazkii.botania.mixin; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import vazkii.botania.api.item.AncientWillContainer; -import vazkii.botania.common.BotaniaStats; import vazkii.botania.common.PlayerAccess; -import vazkii.botania.common.entity.BotaniaEntities; import vazkii.botania.common.item.ResoluteIvyItem; @Mixin(Player.class)