实现盔甲的自定义属性

This commit is contained in:
17146 2025-04-02 17:29:21 +08:00
parent 1415430079
commit d532057dc8
7 changed files with 53 additions and 81 deletions

View file

@ -29,7 +29,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
public class Mod {
public static final String MODID = "superbwarfare";
public static final String ATTRIBUTE_MODIFIER = "superbwarfare_attribute_modifier";
public static final ResourceLocation ATTRIBUTE_MODIFIER = loc("attribute_modifier");
public static final Logger LOGGER = LogManager.getLogger(Mod.class);

View file

@ -0,0 +1,37 @@
package com.atsuishio.superbwarfare.item.armor;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.init.ModAttributes;
import net.minecraft.core.Holder;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import java.util.ArrayList;
public abstract class BulletResistantArmor extends ArmorItem {
private float bulletResistance = 0.1f;
public BulletResistantArmor(Holder<ArmorMaterial> material, Type type, Properties properties) {
super(material, type, properties);
}
public BulletResistantArmor(Holder<ArmorMaterial> material, Type type, Properties properties, float bulletResistance) {
super(material, type, properties);
this.bulletResistance = bulletResistance;
}
@Override
public ItemAttributeModifiers getDefaultAttributeModifiers(ItemStack stack) {
var modifiers = super.getDefaultAttributeModifiers(stack);
var list = new ArrayList<>(modifiers.modifiers());
list.add(new ItemAttributeModifiers.Entry(ModAttributes.BULLET_RESISTANCE, new AttributeModifier(Mod.ATTRIBUTE_MODIFIER,
this.bulletResistance * Math.max(0, 1 - (double) stack.getDamageValue() / stack.getMaxDamage()), AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.bySlot(this.type.getSlot())));
return new ItemAttributeModifiers(list, true);
}
}

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.armor;
import com.atsuishio.superbwarfare.client.renderer.armor.GeHelmetM35ArmorRenderer;
import com.atsuishio.superbwarfare.init.ModArmorMaterials;
import com.atsuishio.superbwarfare.item.CustomRendererArmor;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -11,11 +10,12 @@ import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.renderer.GeoArmorRenderer;
import software.bernie.geckolib.util.GeckoLibUtil;
public class GeHelmetM35 extends ArmorItem implements GeoItem, CustomRendererArmor {
public class GeHelmetM35 extends BulletResistantArmor implements GeoItem, CustomRendererArmor {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public GeHelmetM35() {
super(ModArmorMaterials.STEEL, Type.HELMET, new Properties());
super(ModArmorMaterials.STEEL, Type.HELMET, new Properties().durability(Type.HELMET.getDurability(35)));
}
@Override
@ -23,19 +23,6 @@ public class GeHelmetM35 extends ArmorItem implements GeoItem, CustomRendererArm
return new GeHelmetM35ArmorRenderer();
}
// TODO attribute modifier
// @Override
// 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.1 * Math.max(0, 1 - (double) stack.getDamageValue() / stack.getMaxDamage()), AttributeModifier.Operation.ADDITION));
// }
// return map;
// }
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
}

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.armor;
import com.atsuishio.superbwarfare.client.renderer.armor.RuChest6b43ArmorRenderer;
import com.atsuishio.superbwarfare.init.ModArmorMaterials;
import com.atsuishio.superbwarfare.item.CustomRendererArmor;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -11,11 +10,12 @@ import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.renderer.GeoArmorRenderer;
import software.bernie.geckolib.util.GeckoLibUtil;
public class RuChest6b43 extends ArmorItem implements GeoItem, CustomRendererArmor {
public class RuChest6b43 extends BulletResistantArmor implements GeoItem, CustomRendererArmor {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public RuChest6b43() {
super(ModArmorMaterials.CEMENTED_CARBIDE, Type.CHESTPLATE, new Properties());
super(ModArmorMaterials.CEMENTED_CARBIDE, Type.CHESTPLATE, new Properties().durability(Type.CHESTPLATE.getDurability(50)), 0.5f);
}
@Override
@ -23,19 +23,6 @@ public class RuChest6b43 extends ArmorItem implements GeoItem, CustomRendererArm
return new RuChest6b43ArmorRenderer();
}
// TODO attribute
// @Override
// 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.5 * Math.max(0, 1 - (double) stack.getDamageValue() / stack.getMaxDamage()), AttributeModifier.Operation.ADDITION));
// }
// return map;
// }
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
}

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.armor;
import com.atsuishio.superbwarfare.client.renderer.armor.RuHelmet6b47ArmorRenderer;
import com.atsuishio.superbwarfare.init.ModArmorMaterials;
import com.atsuishio.superbwarfare.item.CustomRendererArmor;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -11,11 +10,12 @@ import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.renderer.GeoArmorRenderer;
import software.bernie.geckolib.util.GeckoLibUtil;
public class RuHelmet6b47 extends ArmorItem implements GeoItem, CustomRendererArmor {
public class RuHelmet6b47 extends BulletResistantArmor implements GeoItem, CustomRendererArmor {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public RuHelmet6b47() {
super(ModArmorMaterials.CEMENTED_CARBIDE, Type.HELMET, new Properties());
super(ModArmorMaterials.CEMENTED_CARBIDE, Type.HELMET, new Properties().durability(Type.HELMET.getDurability(50)), 0.2f);
}
@Override
@ -23,19 +23,6 @@ public class RuHelmet6b47 extends ArmorItem implements GeoItem, CustomRendererAr
return new RuHelmet6b47ArmorRenderer();
}
// todo attribute
// @Override
// 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.2 * Math.max(0, 1 - (double) stack.getDamageValue() / stack.getMaxDamage()), AttributeModifier.Operation.ADDITION));
// }
// return map;
// }
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
}

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.armor;
import com.atsuishio.superbwarfare.client.renderer.armor.UsChestIotvArmorRenderer;
import com.atsuishio.superbwarfare.init.ModArmorMaterials;
import com.atsuishio.superbwarfare.item.CustomRendererArmor;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -11,11 +10,12 @@ import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.renderer.GeoArmorRenderer;
import software.bernie.geckolib.util.GeckoLibUtil;
public class UsChestIotv extends ArmorItem implements GeoItem, CustomRendererArmor {
public class UsChestIotv extends BulletResistantArmor implements GeoItem, CustomRendererArmor {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public UsChestIotv() {
super(ModArmorMaterials.CEMENTED_CARBIDE, Type.CHESTPLATE, new Properties());
super(ModArmorMaterials.CEMENTED_CARBIDE, Type.CHESTPLATE, new Properties().durability(Type.CHESTPLATE.getDurability(50)), 0.5f);
}
@Override
@ -23,19 +23,6 @@ public class UsChestIotv extends ArmorItem implements GeoItem, CustomRendererArm
return new UsChestIotvArmorRenderer();
}
// todo attribute
// @Override
// 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.5 * Math.max(0, 1 - (double) stack.getDamageValue() / stack.getMaxDamage()), AttributeModifier.Operation.ADDITION));
// }
// return map;
// }
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
}

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.armor;
import com.atsuishio.superbwarfare.client.renderer.armor.UsHelmetPastgArmorRenderer;
import com.atsuishio.superbwarfare.init.ModArmorMaterials;
import com.atsuishio.superbwarfare.item.CustomRendererArmor;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -11,11 +10,12 @@ import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.renderer.GeoArmorRenderer;
import software.bernie.geckolib.util.GeckoLibUtil;
public class UsHelmetPastg extends ArmorItem implements GeoItem, CustomRendererArmor {
public class UsHelmetPastg extends BulletResistantArmor implements GeoItem, CustomRendererArmor {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public UsHelmetPastg() {
super(ModArmorMaterials.CEMENTED_CARBIDE, Type.HELMET, new Properties());
super(ModArmorMaterials.CEMENTED_CARBIDE, Type.HELMET, new Properties().durability(Type.HELMET.getDurability(50)), 0.2f);
}
@Override
@ -23,19 +23,6 @@ public class UsHelmetPastg extends ArmorItem implements GeoItem, CustomRendererA
return new UsHelmetPastgArmorRenderer();
}
// todo attribute
// @Override
// 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.2 * Math.max(0, 1 - (double) stack.getDamageValue() / stack.getMaxDamage()), AttributeModifier.Operation.ADDITION));
// }
// return map;
// }
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
}