Skip to content

Commit

Permalink
Combatify 1.2.0 1.20.6 RC 3 Fabric - some banner shield changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra-Myers committed Jul 12, 2024
1 parent 0c294ff commit a006193
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 177 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/atlas/combatify/Combatify.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -49,6 +49,7 @@ public void block(LivingEntity instance, @Nullable Entity entity, ItemStack bloc
}
}
}

bl.set(true);
}

Expand All @@ -59,28 +60,21 @@ 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;
}
return 0;
}

@Override
public @NotNull InteractionResultHolder<ItemStack> 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<Component> 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));
}
}
67 changes: 14 additions & 53 deletions src/main/java/net/atlas/combatify/util/NewShieldBlockingType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -64,26 +50,28 @@ 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
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);
Expand All @@ -101,31 +89,4 @@ public double getShieldKnockbackResistanceValue(ItemStack stack) {
return 0.5;
return 0.25;
}

@Override
public @NotNull InteractionResultHolder<ItemStack> 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<Component> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
67 changes: 67 additions & 0 deletions src/main/java/net/atlas/combatify/util/PercentageBlockingType.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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<Component> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
Loading

0 comments on commit a006193

Please sign in to comment.