Skip to content

Commit 80867f6

Browse files
committed
Fix armor nto having armor values.
1 parent ee6f5c8 commit 80867f6

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

common/src/main/java/generations/gg/generations/core/generationscore/common/world/item/GenerationsArmor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static ArmorSet create(String name, Supplier<ArmorMaterial> armorMaterial
127127
register(name + "_helmet", properties -> new GenerationsArmorItem(armorMaterial.get(), ArmorItem.Type.HELMET, properties)),
128128
register(name + "_chestplate", properties -> new GenerationsArmorItem(armorMaterial.get(), ArmorItem.Type.CHESTPLATE, properties)),
129129
register(name + "_leggings", properties -> new GenerationsArmorItem(armorMaterial.get(), ArmorItem.Type.LEGGINGS, properties)),
130-
register(name + "_boots", properties -> new GenerationsArmorItem(armorMaterial.get(), ArmorItem.Type.BOOTS, properties).addArmorEffects(armorEffects)),
130+
register(name + "_boots", properties -> new GenerationsArmorItem(armorMaterial.get(), ArmorItem.Type.BOOTS, properties, armorEffects)),
131131
armorMaterial
132132
);
133133
}

common/src/main/java/generations/gg/generations/core/generationscore/common/world/item/armor/GenerationsArmorItem.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,38 @@
33
import com.google.common.collect.ImmutableMultimap;
44
import com.google.common.collect.Multimap;
55
import dev.architectury.extensions.ItemExtension;
6+
import net.minecraft.Util;
7+
import net.minecraft.world.InteractionHand;
8+
import net.minecraft.world.InteractionResultHolder;
69
import net.minecraft.world.entity.Entity;
710
import net.minecraft.world.entity.EquipmentSlot;
811
import net.minecraft.world.entity.ai.attributes.Attribute;
912
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
13+
import net.minecraft.world.entity.ai.attributes.Attributes;
1014
import net.minecraft.world.entity.player.Player;
11-
import net.minecraft.world.item.ArmorItem;
12-
import net.minecraft.world.item.ArmorMaterial;
13-
import net.minecraft.world.item.ItemStack;
15+
import net.minecraft.world.item.*;
1416
import net.minecraft.world.level.Level;
1517
import org.jetbrains.annotations.NotNull;
18+
import org.jetbrains.annotations.Nullable;
1619

17-
import java.util.Collection;
18-
import java.util.HashSet;
19-
import java.util.Set;
20+
import java.util.*;
2021
import java.util.function.Consumer;
2122
import java.util.stream.Collectors;
2223

2324
public class GenerationsArmorItem extends ArmorItem implements ItemExtension {
2425
public final Set<ArmorTickEffect> armorEffects = new HashSet<>();
2526
public final Set<CustomAttributeModifier> customAttributeModifiers = new HashSet<>();
2627

27-
public GenerationsArmorItem(ArmorMaterial armorMaterial, Type equipmentSlot, Properties properties) {
28+
public GenerationsArmorItem(ArmorMaterial armorMaterial, Type equipmentSlot, Properties properties, ArmorEffect... armorEffects) {
2829
super(armorMaterial, equipmentSlot, properties);
29-
}
3030

31-
public GenerationsArmorItem addArmorEffects(ArmorEffect... armorEffects) {
3231
for (ArmorEffect armorEffect : armorEffects) {
3332
if (armorEffect instanceof ArmorTickEffect effect) {
3433
this.armorEffects.add(effect);
3534
} else if (armorEffect instanceof CustomAttributeModifier effect) {
3635
this.customAttributeModifiers.add(effect);
3736
}
3837
}
39-
return this;
4038
}
4139

4240
//Method for Forge
@@ -46,6 +44,8 @@ public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlo
4644
customAttributeModifier.getAttributeModifiers(builder, equipmentSlot, itemStack, this);
4745
}
4846

47+
builder.putAll(this.getDefaultAttributeModifiers(equipmentSlot));
48+
4949
return builder.build();
5050
}
5151

common/src/main/java/generations/gg/generations/core/generationscore/common/world/item/armor/GenerationsArmorMaterials.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import com.google.common.base.Suppliers;
55
import generations.gg.generations.core.generationscore.common.GenerationsCore;
66
import generations.gg.generations.core.generationscore.common.world.item.GenerationsItems;
7+
import net.minecraft.Util;
78
import net.minecraft.sounds.SoundEvent;
89
import net.minecraft.sounds.SoundEvents;
910
import net.minecraft.world.item.*;
1011
import net.minecraft.world.item.crafting.Ingredient;
1112
import org.jetbrains.annotations.NotNull;
1213

14+
import java.util.EnumMap;
1315
import java.util.function.Supplier;
1416

1517
public enum GenerationsArmorMaterials implements ArmorMaterial {
@@ -39,7 +41,7 @@ public enum GenerationsArmorMaterials implements ArmorMaterial {
3941

4042
private final String name;
4143
private final int durabilityMultiplier;
42-
private final int[] slotProtections;
44+
private final EnumMap<ArmorItem.Type, Integer> slotProtections;
4345
private final int enchantmentValue;
4446
private final SoundEvent sound;
4547
private final float toughness;
@@ -49,7 +51,12 @@ public enum GenerationsArmorMaterials implements ArmorMaterial {
4951
GenerationsArmorMaterials(String name, int durabilityMultiplier, int[] slotProtections, int enchantmentValue, Supplier<Item> repairIngredient, float toughness, float knockbackResistance) {
5052
this.name = GenerationsCore.MOD_ID + ":" + name;
5153
this.durabilityMultiplier = durabilityMultiplier;
52-
this.slotProtections = slotProtections;
54+
this.slotProtections = Util.make(new EnumMap<ArmorItem.Type, Integer>(ArmorItem.Type.class), map -> {
55+
map.put(ArmorItem.Type.BOOTS, slotProtections[0]);
56+
map.put(ArmorItem.Type.LEGGINGS, slotProtections[1]);
57+
map.put(ArmorItem.Type.CHESTPLATE, slotProtections[2]);
58+
map.put(ArmorItem.Type.HELMET, slotProtections[3]);
59+
});
5360
this.enchantmentValue = enchantmentValue;
5461
this.sound = SoundEvents.ARMOR_EQUIP_IRON;
5562
this.toughness = toughness;
@@ -68,7 +75,7 @@ public int getDurabilityForType(ArmorItem.@NotNull Type type) {
6875

6976
@Override
7077
public int getDefenseForType(ArmorItem.Type type) {
71-
return this.slotProtections[type.getSlot().getIndex()];
78+
return this.slotProtections.get(type);
7279
}
7380

7481
public int getEnchantmentValue() {

0 commit comments

Comments
 (0)