From a006193ad0f345a35b3b36ac4e21985b44ad2fe9 Mon Sep 17 00:00:00 2001 From: Alexandra-Myers Date: Fri, 12 Jul 2024 00:25:30 -0400 Subject: [PATCH] Combatify 1.2.0 1.20.6 RC 3 Fabric - some banner shield changes --- .../java/net/atlas/combatify/Combatify.java | 1 + .../util/CurrentShieldBlockingType.java | 34 ++++---- .../combatify/util/NewShieldBlockingType.java | 67 ++++----------- .../util/NonBannerShieldBlockingType.java | 39 +++++++++ .../util/PercentageBlockingType.java | 67 +++++++++++++++ .../combatify/util/ShieldBlockingType.java | 7 +- .../combatify/util/SwordBlockingType.java | 47 ++++------- .../combatify/util/TestBlockingType.java | 81 +++---------------- 8 files changed, 166 insertions(+), 177 deletions(-) create mode 100644 src/main/java/net/atlas/combatify/util/NonBannerShieldBlockingType.java create mode 100644 src/main/java/net/atlas/combatify/util/PercentageBlockingType.java diff --git a/src/main/java/net/atlas/combatify/Combatify.java b/src/main/java/net/atlas/combatify/Combatify.java index fefab43..aaddd2e 100644 --- a/src/main/java/net/atlas/combatify/Combatify.java +++ b/src/main/java/net/atlas/combatify/Combatify.java @@ -74,6 +74,7 @@ public class Combatify implements ModInitializer { public static final PrefixLogger LOGGER = new PrefixLogger(LogManager.getLogger("Combatify")); public static final BlockingType SWORD = defineDefaultBlockingType(new SwordBlockingType("sword").setToolBlocker(true).setDisablement(false).setCrouchable(false).setBlockHit(true).setRequireFullCharge(false).setSwordBlocking(true).setDelay(false)); public static final BlockingType SHIELD = defineDefaultBlockingType(new ShieldBlockingType("shield")); + public static final BlockingType SHIELD_NO_BANNER = defineDefaultBlockingType(new ShieldBlockingType("shield_no_banner")); public static final BlockingType CURRENT_SHIELD = defineDefaultBlockingType(new CurrentShieldBlockingType("current_shield")); public static final BlockingType NEW_SHIELD = defineDefaultBlockingType(new NewShieldBlockingType("new_shield").setKbMechanics(false)); public static final BlockingType EMPTY = new EmptyBlockingType("empty").setDisablement(false).setCrouchable(false).setRequireFullCharge(false).setKbMechanics(false); diff --git a/src/main/java/net/atlas/combatify/util/CurrentShieldBlockingType.java b/src/main/java/net/atlas/combatify/util/CurrentShieldBlockingType.java index 1b45432..9dcdeda 100644 --- a/src/main/java/net/atlas/combatify/util/CurrentShieldBlockingType.java +++ b/src/main/java/net/atlas/combatify/util/CurrentShieldBlockingType.java @@ -4,26 +4,26 @@ import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef; import net.atlas.combatify.Combatify; import net.atlas.combatify.config.ConfigurableItemData; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.tags.DamageTypeTags; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.Arrow; import net.minecraft.world.entity.projectile.SpectralArrow; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; +import net.minecraft.world.item.component.ItemAttributeModifiers; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; import static net.atlas.combatify.util.MethodHandler.arrowDisable; -public class CurrentShieldBlockingType extends BlockingType { +public class CurrentShieldBlockingType extends ShieldBlockingType { public CurrentShieldBlockingType(String name) { super(name); } @@ -49,6 +49,7 @@ public void block(LivingEntity instance, @Nullable Entity entity, ItemStack bloc } } } + bl.set(true); } @@ -59,7 +60,7 @@ public float getShieldBlockDamageValue(ItemStack stack) { @Override public double getShieldKnockbackResistanceValue(ItemStack stack) { - if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { + if (Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem()); if (configurableItemData.blockKbRes != null) return configurableItemData.blockKbRes; @@ -67,20 +68,13 @@ public double getShieldKnockbackResistanceValue(ItemStack stack) { return 0; } - @Override - public @NotNull InteractionResultHolder use(Level world, Player player, InteractionHand interactionHand) { - ItemStack itemStack = player.getItemInHand(interactionHand); - player.startUsingItem(interactionHand); - return InteractionResultHolder.consume(itemStack); - } - - @Override - public boolean canUse(Level world, Player user, InteractionHand hand) { - return true; - } - - @Override + @Override public void appendTooltipInfo(Consumer consumer, Player player, ItemStack stack) { - + double g = getShieldKnockbackResistanceValue(stack); + if (g > 0.0) + consumer.accept(CommonComponents.space().append( + Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_VALUE.id(), + ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format(g * 10.0), + Component.translatable("attribute.name.generic.knockback_resistance"))).withStyle(ChatFormatting.DARK_GREEN)); } } diff --git a/src/main/java/net/atlas/combatify/util/NewShieldBlockingType.java b/src/main/java/net/atlas/combatify/util/NewShieldBlockingType.java index 2599941..e522e6a 100644 --- a/src/main/java/net/atlas/combatify/util/NewShieldBlockingType.java +++ b/src/main/java/net/atlas/combatify/util/NewShieldBlockingType.java @@ -3,52 +3,38 @@ import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef; import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef; import net.atlas.combatify.Combatify; -import net.atlas.combatify.config.ArrowDisableMode; import net.atlas.combatify.config.ConfigurableItemData; -import net.atlas.combatify.enchantment.CustomEnchantmentHelper; import net.atlas.combatify.enchantment.DefendingEnchantment; import net.atlas.combatify.extensions.ExtendedTier; import net.atlas.combatify.extensions.ItemExtensions; -import net.atlas.combatify.extensions.PlayerExtensions; -import net.minecraft.ChatFormatting; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; import net.minecraft.tags.DamageTypeTags; import net.minecraft.util.Mth; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.Arrow; import net.minecraft.world.entity.projectile.SpectralArrow; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; -import net.minecraft.world.item.component.ItemAttributeModifiers; import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.function.Consumer; - import static net.atlas.combatify.util.MethodHandler.arrowDisable; -public class NewShieldBlockingType extends BlockingType { +public class NewShieldBlockingType extends PercentageBlockingType { public NewShieldBlockingType(String name) { super(name); } @Override - public void block(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl) { - if (instance instanceof Player player && player.getCooldowns().isOnCooldown(blockingItem.getItem())) - return; - float actualStrength = this.getShieldBlockDamageValue(blockingItem); - g.set(amount.get() * actualStrength); + public boolean canBlock(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl) { + return !(instance instanceof Player player) || !player.getCooldowns().isOnCooldown(blockingItem.getItem()); + } + + @Override + public boolean fulfilBlock(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl, float actualStrength) { + boolean hurt = false; if (source.is(DamageTypeTags.IS_EXPLOSION) || source.is(DamageTypeTags.IS_PROJECTILE)) { g.set(amount.get()); switch (source.getDirectEntity()) { @@ -64,13 +50,15 @@ public void block(LivingEntity instance, @Nullable Entity entity, ItemStack bloc entity = source.getDirectEntity(); if (entity instanceof LivingEntity livingEntity) { instance.hurtCurrentlyUsedShield(g.get()); + hurt = true; instance.blockUsingShield(livingEntity); } } - instance.hurtCurrentlyUsedShield(g.get()); - amount.set(amount.get() - g.get()); + if (!hurt) + instance.hurtCurrentlyUsedShield(g.get()); bl.set(true); + return true; } @Override @@ -78,12 +66,12 @@ public float getShieldBlockDamageValue(ItemStack stack) { if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem()); if (configurableItemData.blockStrength != null) - return (float) (configurableItemData.blockStrength / 100.0) + (EnchantmentHelper.getItemEnchantmentLevel(DefendingEnchantment.DEFENDER, stack) * 0.1F); + return (float) (configurableItemData.blockStrength / 100.0) + (Combatify.CONFIG.defender() ? EnchantmentHelper.getItemEnchantmentLevel(DefendingEnchantment.DEFENDER, stack) * 0.1F : 0); } Tier tier = ((ItemExtensions) stack.getItem()).getConfigTier(); float strengthIncrease = ExtendedTier.getLevel(tier) / 2F - 2F; strengthIncrease = Mth.ceil(strengthIncrease); - if(Combatify.CONFIG.defender()) + if (Combatify.CONFIG.defender()) strengthIncrease += EnchantmentHelper.getItemEnchantmentLevel(DefendingEnchantment.DEFENDER, stack); return Math.min(0.5F + (strengthIncrease * 0.1F), 1); @@ -101,31 +89,4 @@ public double getShieldKnockbackResistanceValue(ItemStack stack) { return 0.5; return 0.25; } - - @Override - public @NotNull InteractionResultHolder use(Level world, Player player, InteractionHand interactionHand) { - ItemStack itemStack = player.getItemInHand(interactionHand); - player.startUsingItem(interactionHand); - return InteractionResultHolder.consume(itemStack); - } - - @Override - public boolean canUse(Level world, Player user, InteractionHand hand) { - return true; - } - - @Override - public void appendTooltipInfo(Consumer consumer, Player player, ItemStack stack) { - float f = getShieldBlockDamageValue(stack); - double g = getShieldKnockbackResistanceValue(stack); - consumer.accept(CommonComponents.space().append( - Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL.id(), - ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format((double) f * 100), - Component.translatable("attribute.name.generic.sword_block_strength"))).withStyle(ChatFormatting.DARK_GREEN)); - if (g > 0.0) - consumer.accept(CommonComponents.space().append( - Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_VALUE.id(), - ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format(g * 10.0), - Component.translatable("attribute.name.generic.knockback_resistance"))).withStyle(ChatFormatting.DARK_GREEN)); - } } diff --git a/src/main/java/net/atlas/combatify/util/NonBannerShieldBlockingType.java b/src/main/java/net/atlas/combatify/util/NonBannerShieldBlockingType.java new file mode 100644 index 0000000..b1493ca --- /dev/null +++ b/src/main/java/net/atlas/combatify/util/NonBannerShieldBlockingType.java @@ -0,0 +1,39 @@ +package net.atlas.combatify.util; + +import net.atlas.combatify.Combatify; +import net.atlas.combatify.config.ConfigurableItemData; +import net.atlas.combatify.enchantment.DefendingEnchantment; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; + +public class NonBannerShieldBlockingType extends ShieldBlockingType { + public NonBannerShieldBlockingType(String name) { + super(name); + } + @Override + public float getShieldBlockDamageValue(ItemStack stack) { + if (Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { + ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem()); + if (configurableItemData.blockStrength != null) { + return configurableItemData.blockStrength.floatValue(); + } + } + float f = 5.0F; + if (Combatify.CONFIG.defender()) + f += EnchantmentHelper.getItemEnchantmentLevel(DefendingEnchantment.DEFENDER, stack); + + return f; + } + + @Override + public double getShieldKnockbackResistanceValue(ItemStack stack) { + if (Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { + ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem()); + if (configurableItemData.blockKbRes != null) { + return configurableItemData.blockKbRes; + } + } + + return 0.5; + } +} diff --git a/src/main/java/net/atlas/combatify/util/PercentageBlockingType.java b/src/main/java/net/atlas/combatify/util/PercentageBlockingType.java new file mode 100644 index 0000000..f64abaf --- /dev/null +++ b/src/main/java/net/atlas/combatify/util/PercentageBlockingType.java @@ -0,0 +1,67 @@ +package net.atlas.combatify.util; + +import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef; +import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.ItemAttributeModifiers; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Consumer; + +public abstract class PercentageBlockingType extends BlockingType { + public PercentageBlockingType(String name) { + super(name); + } + + @Override + public void block(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl) { + if (!canBlock(instance, entity, blockingItem, source, amount, f, g, bl)) return; + float actualStrength = this.getShieldBlockDamageValue(blockingItem); + g.set(amount.get() * actualStrength); + if (!fulfilBlock(instance, entity, blockingItem, source, amount, f, g, bl, actualStrength)) return; + + amount.set(amount.get() - g.get()); + } + public abstract boolean canBlock(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl); + + public abstract boolean fulfilBlock(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl, float actualStrength); + + @Override + public @NotNull InteractionResultHolder use(Level world, Player player, InteractionHand interactionHand) { + ItemStack itemStack = player.getItemInHand(interactionHand); + player.startUsingItem(interactionHand); + return InteractionResultHolder.consume(itemStack); + } + + @Override + public boolean canUse(Level world, Player user, InteractionHand hand) { + return true; + } + + @Override + public void appendTooltipInfo(Consumer consumer, Player player, ItemStack stack) { + float f = getShieldBlockDamageValue(stack); + double g = getShieldKnockbackResistanceValue(stack); + consumer.accept(CommonComponents.space().append( + Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL.id(), + ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format((double) f * 100), + Component.translatable("attribute.name.generic.sword_block_strength"))).withStyle(ChatFormatting.DARK_GREEN)); + if (g > 0.0) + consumer.accept(CommonComponents.space().append( + Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_VALUE.id(), + ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format(g * 10.0), + Component.translatable("attribute.name.generic.knockback_resistance"))).withStyle(ChatFormatting.DARK_GREEN)); + } +} diff --git a/src/main/java/net/atlas/combatify/util/ShieldBlockingType.java b/src/main/java/net/atlas/combatify/util/ShieldBlockingType.java index 1d5141f..fc4eeb1 100644 --- a/src/main/java/net/atlas/combatify/util/ShieldBlockingType.java +++ b/src/main/java/net/atlas/combatify/util/ShieldBlockingType.java @@ -65,7 +65,7 @@ public void block(LivingEntity instance, @Nullable Entity entity, ItemStack bloc @Override public float getShieldBlockDamageValue(ItemStack stack) { - if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { + if (Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem()); if (configurableItemData.blockStrength != null) { return configurableItemData.blockStrength.floatValue(); @@ -74,15 +74,16 @@ public float getShieldBlockDamageValue(ItemStack stack) { BannerPatternLayers bannerPatternLayers = stack.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY); DyeColor dyeColor = stack.get(DataComponents.BASE_COLOR); float f = !bannerPatternLayers.layers().isEmpty() || dyeColor != null ? 10.0F : 5.0F; - if(Combatify.CONFIG.defender()) { + if (Combatify.CONFIG.defender()) { f += EnchantmentHelper.getItemEnchantmentLevel(DefendingEnchantment.DEFENDER, stack); } + return f; } @Override public double getShieldKnockbackResistanceValue(ItemStack stack) { - if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { + if (Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem()); if (configurableItemData.blockKbRes != null) { return configurableItemData.blockKbRes; diff --git a/src/main/java/net/atlas/combatify/util/SwordBlockingType.java b/src/main/java/net/atlas/combatify/util/SwordBlockingType.java index ae972ba..1c2b71d 100644 --- a/src/main/java/net/atlas/combatify/util/SwordBlockingType.java +++ b/src/main/java/net/atlas/combatify/util/SwordBlockingType.java @@ -28,23 +28,23 @@ import java.util.function.Consumer; -public class SwordBlockingType extends BlockingType { +public class SwordBlockingType extends PercentageBlockingType { public SwordBlockingType(String name) { super(name); } @Override - public void block(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl) { - if(instance.getItemInHand(InteractionHand.OFF_HAND).isEmpty()) { - boolean blocked = !source.is(DamageTypeTags.IS_EXPLOSION) && !source.is(DamageTypeTags.IS_PROJECTILE); - float actualStrength = this.getShieldBlockDamageValue(blockingItem); - g.set(amount.get() * actualStrength); - entity = source.getDirectEntity(); - if (blocked && entity instanceof LivingEntity) - instance.blockUsingShield((LivingEntity) entity); + public boolean canBlock(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl) { + return instance.getItemInHand(InteractionHand.OFF_HAND).isEmpty(); + } - amount.set(amount.get() - g.get()); - } + @Override + public boolean fulfilBlock(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl, float actualStrength) { + boolean blocked = !source.is(DamageTypeTags.IS_EXPLOSION) && !source.is(DamageTypeTags.IS_PROJECTILE); + entity = source.getDirectEntity(); + if (blocked && entity instanceof LivingEntity) + instance.blockUsingShield((LivingEntity) entity); + return true; } @Override @@ -72,11 +72,11 @@ public double getShieldKnockbackResistanceValue(ItemStack stack) { } @Override - public @NotNull InteractionResultHolder use(Level world, Player user, InteractionHand hand) { - ItemStack itemStack = user.getItemInHand(hand); - if(user.isSprinting()) - user.setSprinting(false); - user.startUsingItem(hand); + public @NotNull InteractionResultHolder use(Level world, Player player, InteractionHand hand) { + ItemStack itemStack = player.getItemInHand(hand); + if (player.isSprinting()) + player.setSprinting(false); + player.startUsingItem(hand); return InteractionResultHolder.consume(itemStack); } @@ -85,19 +85,4 @@ public boolean canUse(Level world, Player user, InteractionHand hand) { ItemStack oppositeStack = user.getItemInHand(InteractionHand.OFF_HAND); return hand != InteractionHand.OFF_HAND && oppositeStack.isEmpty() && Combatify.CONFIG.swordBlocking(); } - - @Override - public void appendTooltipInfo(Consumer consumer, Player player, ItemStack stack) { - float f = getShieldBlockDamageValue(stack); - double g = getShieldKnockbackResistanceValue(stack); - consumer.accept(CommonComponents.space().append( - Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL.id(), - ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format((double) f * 100), - Component.translatable("attribute.name.generic.sword_block_strength"))).withStyle(ChatFormatting.DARK_GREEN)); - if (g > 0.0) - consumer.accept(CommonComponents.space().append( - Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_VALUE.id(), - ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format(g * 10.0), - Component.translatable("attribute.name.generic.knockback_resistance"))).withStyle(ChatFormatting.DARK_GREEN)); - } } diff --git a/src/main/java/net/atlas/combatify/util/TestBlockingType.java b/src/main/java/net/atlas/combatify/util/TestBlockingType.java index b011627..10c2c1f 100644 --- a/src/main/java/net/atlas/combatify/util/TestBlockingType.java +++ b/src/main/java/net/atlas/combatify/util/TestBlockingType.java @@ -4,69 +4,40 @@ import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef; import net.atlas.combatify.Combatify; import net.atlas.combatify.config.ConfigurableItemData; -import net.atlas.combatify.enchantment.DefendingEnchantment; import net.atlas.combatify.extensions.ExtendedTier; import net.atlas.combatify.extensions.ItemExtensions; -import net.minecraft.ChatFormatting; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; import net.minecraft.tags.DamageTypeTags; -import net.minecraft.util.Mth; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.attributes.AttributeModifier; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; -import net.minecraft.world.item.component.ItemAttributeModifiers; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.function.Consumer; - -public class TestBlockingType extends BlockingType { +public class TestBlockingType extends SwordBlockingType { public TestBlockingType(String name) { super(name); } @Override - public void block(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl) { - float actualStrength = this.getShieldBlockDamageValue(blockingItem); - g.set(amount.get() * actualStrength); - if (source.is(DamageTypeTags.IS_EXPLOSION) || source.is(DamageTypeTags.IS_PROJECTILE)) + public boolean fulfilBlock(LivingEntity instance, @Nullable Entity entity, ItemStack blockingItem, DamageSource source, LocalFloatRef amount, LocalFloatRef f, LocalFloatRef g, LocalBooleanRef bl, float actualStrength) { + boolean hurt = false; + if (source.is(DamageTypeTags.IS_EXPLOSION) || source.is(DamageTypeTags.IS_PROJECTILE)) { g.set(amount.get()); - else { + } else { entity = source.getDirectEntity(); - if (entity instanceof LivingEntity) { + if (entity instanceof LivingEntity livingEntity) { instance.hurtCurrentlyUsedShield(g.get()); - instance.blockUsingShield((LivingEntity) entity); + hurt = true; + instance.blockUsingShield(livingEntity); } - bl.set(true); } - instance.hurtCurrentlyUsedShield(g.get()); - amount.set(amount.get() - g.get()); + if (!hurt) + instance.hurtCurrentlyUsedShield(g.get()); + return true; } - @Override - public float getShieldBlockDamageValue(ItemStack stack) { - if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { - ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem()); - if (configurableItemData.blockStrength != null) - return (float) (configurableItemData.blockStrength / 100.0) + (EnchantmentHelper.getItemEnchantmentLevel(DefendingEnchantment.DEFENDER, stack) * 0.1F); - } - Tier tier = ((ItemExtensions) stack.getItem()).getConfigTier(); - float strengthIncrease = ExtendedTier.getLevel(tier) / 2F - 2F; - strengthIncrease = Mth.ceil(strengthIncrease); - if (Combatify.CONFIG.defender()) - strengthIncrease += EnchantmentHelper.getItemEnchantmentLevel(DefendingEnchantment.DEFENDER, stack); - return Math.min(0.5F + (strengthIncrease * 0.1F), 1); - } @Override public double getShieldKnockbackResistanceValue(ItemStack stack) { if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) { @@ -79,34 +50,4 @@ public double getShieldKnockbackResistanceValue(ItemStack stack) { return 0.5; return 0.25; } - - @Override - public @NotNull InteractionResultHolder use(Level world, Player user, InteractionHand hand) { - ItemStack itemStack = user.getItemInHand(hand); - if(user.isSprinting()) { - user.setSprinting(false); - } - user.startUsingItem(hand); - return InteractionResultHolder.consume(itemStack); - } - - @Override - public boolean canUse(Level world, Player user, InteractionHand hand) { - return true; - } - - @Override - public void appendTooltipInfo(Consumer consumer, Player player, ItemStack stack) { - float f = getShieldBlockDamageValue(stack); - double g = getShieldKnockbackResistanceValue(stack); - consumer.accept(CommonComponents.space().append( - Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL.id(), - ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format((double) f * 100), - Component.translatable("attribute.name.generic.sword_block_strength"))).withStyle(ChatFormatting.DARK_GREEN)); - if (g > 0.0) - consumer.accept(CommonComponents.space().append( - Component.translatable("attribute.modifier.equals." + AttributeModifier.Operation.ADD_VALUE.id(), - ItemAttributeModifiers.ATTRIBUTE_MODIFIER_FORMAT.format(g * 10.0), - Component.translatable("attribute.name.generic.knockback_resistance"))).withStyle(ChatFormatting.DARK_GREEN)); - } }