-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combatify 1.2.0 1.20.6 RC 3 Fabric - some banner shield changes
- Loading branch information
1 parent
0c294ff
commit a006193
Showing
8 changed files
with
166 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/net/atlas/combatify/util/NonBannerShieldBlockingType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
src/main/java/net/atlas/combatify/util/PercentageBlockingType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.