实现了装备的动态属性

This commit is contained in:
17146 2024-09-26 10:37:04 +08:00
parent 14bae3e12e
commit 69c4efd6b2
2 changed files with 14 additions and 12 deletions

View file

@ -25,6 +25,7 @@ import java.util.function.Consumer;
public class RuChest6b43 extends ArmorItem implements GeoItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public RuChest6b43() {
super(ModArmorMaterial.CEMENTED_CARBIDE, Type.CHESTPLATE, new Properties());
}
@ -45,13 +46,13 @@ public class RuChest6b43 extends ArmorItem implements GeoItem {
}
@Override
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) {
Multimap<Attribute, AttributeModifier> map = super.getDefaultAttributeModifiers(equipmentSlot);
UUID uuid = new UUID(equipmentSlot.toString().hashCode(), 0);
if (equipmentSlot == EquipmentSlot.CHEST) {
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack) {
Multimap<Attribute, AttributeModifier> map = super.getDefaultAttributeModifiers(slot);
UUID uuid = new UUID(slot.toString().hashCode(), 0);
if (slot == EquipmentSlot.CHEST) {
map = HashMultimap.create(map);
map.put(ModAttributes.BULLET_RESISTANCE.get(), new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER, 0.5f, AttributeModifier.Operation.ADDITION));
map.put(ModAttributes.BULLET_RESISTANCE.get(), new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER,
0.5 * Math.max(0, 1 - (double) stack.getDamageValue() / stack.getMaxDamage()), AttributeModifier.Operation.ADDITION));
}
return map;
}

View file

@ -25,6 +25,7 @@ import java.util.function.Consumer;
public class RuHelmet6b47 extends ArmorItem implements GeoItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public RuHelmet6b47() {
super(ModArmorMaterial.CEMENTED_CARBIDE, Type.HELMET, new Properties());
}
@ -45,13 +46,13 @@ public class RuHelmet6b47 extends ArmorItem implements GeoItem {
}
@Override
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) {
Multimap<Attribute, AttributeModifier> map = super.getDefaultAttributeModifiers(equipmentSlot);
UUID uuid = new UUID(equipmentSlot.toString().hashCode(), 0);
if (equipmentSlot == EquipmentSlot.HEAD) {
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack) {
Multimap<Attribute, AttributeModifier> map = super.getDefaultAttributeModifiers(slot);
UUID uuid = new UUID(slot.toString().hashCode(), 0);
if (slot == EquipmentSlot.HEAD) {
map = HashMultimap.create(map);
map.put(ModAttributes.BULLET_RESISTANCE.get(), new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER, 0.2f, AttributeModifier.Operation.ADDITION));
map.put(ModAttributes.BULLET_RESISTANCE.get(), new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER,
0.2 * Math.max(0, 1 - (double) stack.getDamageValue() / stack.getMaxDamage()), AttributeModifier.Operation.ADDITION));
}
return map;
}