11package generations.gg.generations.core.generationscore.common.world.item
22
33import generations.gg.generations.core.generationscore.common.GenerationsCore
4+ import generations.gg.generations.core.generationscore.common.generationsResource
45import generations.gg.generations.core.generationscore.common.tab
56import generations.gg.generations.core.generationscore.common.util.ItemPlatformRegistry
67import generations.gg.generations.core.generationscore.common.world.item.armor.ArmorEffect
@@ -11,8 +12,13 @@ import generations.gg.generations.core.generationscore.common.world.item.armor.e
1112import generations.gg.generations.core.generationscore.common.world.item.armor.effects.SpeedModifier
1213import net.minecraft.core.Holder
1314import net.minecraft.resources.ResourceKey
15+ import net.minecraft.resources.ResourceLocation
1416import net.minecraft.world.effect.MobEffect
1517import net.minecraft.world.effect.MobEffects
18+ import net.minecraft.world.entity.EquipmentSlotGroup
19+ import net.minecraft.world.entity.ai.attributes.Attribute
20+ import net.minecraft.world.entity.ai.attributes.AttributeModifier
21+ import net.minecraft.world.entity.ai.attributes.Attributes
1622import net.minecraft.world.item.*
1723import net.minecraft.world.item.enchantment.Enchantment
1824import net.minecraft.world.item.enchantment.Enchantments
@@ -29,71 +35,71 @@ object GenerationsArmor: ItemPlatformRegistry() {
2935 ): Holder <Item > = create(name, { function.invoke(of()).tab(tab) })
3036
3137 val AETHER : ArmorSet = ArmorSet .create(" aether" , GenerationsArmorMaterials .AETHER ) {
32- speed( 0.5 )
38+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
3339 }
3440
3541 val AQUA : ArmorSet = ArmorSet .create(" aqua" , GenerationsArmorMaterials .AQUA )
3642 val FLARE : ArmorSet = ArmorSet .create(" flare" , GenerationsArmorMaterials .FLARE )
3743 val GALACTIC : ArmorSet = ArmorSet .create(" galactic" , GenerationsArmorMaterials .GALACTIC ) {
38- speed( 0.5 )
44+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
3945 }
4046 val ULTRITE : ArmorSet = ArmorSet .create(" ultrite" , GenerationsArmorMaterials .ULTRITE )
4147 val MAGMA : ArmorSet = ArmorSet .create(" magma" , GenerationsArmorMaterials .MAGMA )
4248 val NEO_PLASMA : ArmorSet = ArmorSet .create(" neo_plasma" , GenerationsArmorMaterials .NEO_PLASMA )
4349 val PLASMA : ArmorSet = ArmorSet .create(" plasma" , GenerationsArmorMaterials .PLASMA )
4450 val ROCKET : ArmorSet = ArmorSet .create(" rocket" , GenerationsArmorMaterials .ROCKET )
4551 val SKULL : ArmorSet = ArmorSet .create(" skull" , GenerationsArmorMaterials .SKULL ) {
46- speed( 0.5 )
52+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
4753 }
4854 val ULTRA : ArmorSet = ArmorSet .create(" ultra" , GenerationsArmorMaterials .ULTRA ) {
4955 potion(MobEffects .MOVEMENT_SPEED , 1 )
50- speed( 0.25 )
56+ speedAttribute( EquipmentSlotGroup . FEET , 0.25 )
5157 }
5258 val CRYSTALLIZED : ArmorSet = ArmorSet .create(" crystallized" , GenerationsArmorMaterials .CRYSTAL ) {
5359 potion(MobEffects .MOVEMENT_SPEED , 1 )
54- speed( 0.1 )
60+ speedAttribute( EquipmentSlotGroup . FEET , 0.1 )
5561 }
5662 val DAWN_STONE : ArmorSet = ArmorSet .create(" dawn_stone" , GenerationsArmorMaterials .DAWN_STONE ) {
5763 potion(MobEffects .JUMP , 3 )
58- speed( 0.5 )
64+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
5965 }
6066 val DUSK_STONE : ArmorSet = ArmorSet .create(" dusk_stone" , GenerationsArmorMaterials .DUSK_STONE ) {
6167 potion(MobEffects .SATURATION , 4 )
62- speed( 0.5 )
68+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
6369 }
6470 val FIRE_STONE : ArmorSet = ArmorSet .create(" fire_stone" , GenerationsArmorMaterials .FIRE_STONE ) {
6571 enchantment(Enchantments .FIRE_PROTECTION , 2 )
6672 potion(MobEffects .FIRE_RESISTANCE , 1 )
67- speed( 0.5 )
73+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
6874 }
6975
7076 val LEAF_STONE : ArmorSet = ArmorSet .create(" leaf_stone" , GenerationsArmorMaterials .LEAF_STONE ) {
7177 enchantment(Enchantments .FEATHER_FALLING , 3 )
7278 enchantment(Enchantments .THORNS , 3 )
73- speed( 0.5 )
79+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
7480 }
7581 val ICE_STONE : ArmorSet = ArmorSet .create(" ice_stone" , GenerationsArmorMaterials .ICE_STONE ) {
7682 enchantment(Enchantments .FROST_WALKER , 2 )
77- speed( 0.5 )
83+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
7884 }
7985 val MOON_STONE : ArmorSet = ArmorSet .create(" moon_stone" , GenerationsArmorMaterials .MOON_STONE ) {
8086 enchantment(Enchantments .PROTECTION , 4 )
8187 enchantment(Enchantments .PROJECTILE_PROTECTION , 4 )
82- speed( 0.5 )
88+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
8389 }
8490 val SUN_STONE : ArmorSet = ArmorSet .create(" sun_stone" , GenerationsArmorMaterials .SUN_STONE ) {
8591 enchantment(Enchantments .PROTECTION , 4 )
8692 enchantment(Enchantments .PROJECTILE_PROTECTION , 4 )
87- speed( 0.5 )
93+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
8894 }
8995 val THUNDER_STONE : ArmorSet = ArmorSet .create(" thunder_stone" , GenerationsArmorMaterials .THUNDER_STONE ) {
9096 potion(MobEffects .DIG_SPEED , 1 )
91- speed( 0.5 )
97+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
9298 }
9399 val WATER_STONE : ArmorSet = ArmorSet .create(" water_stone" , GenerationsArmorMaterials .WATER_STONE ) {
94100 potion(MobEffects .WATER_BREATHING , 1 )
95101 enchantment(Enchantments .AQUA_AFFINITY , 2 )
96- speed( 0.5 )
102+ speedAttribute( EquipmentSlotGroup . FEET , 0.5 )
97103 }
98104
99105 fun of (): Item .Properties {
@@ -124,6 +130,7 @@ object GenerationsArmor: ItemPlatformRegistry() {
124130
125131 class Builder (private val name : String , private val armormaterial : Holder <ArmorMaterial >) {
126132 private val effects: MutableList <ArmorEffect > = ArrayList ()
133+ private val data: MutableMap <EquipmentSlotGroup , MutableList <Pair <Holder <Attribute >, AttributeModifier >>> = mutableMapOf ()
127134
128135 fun enchantment (enchantment : ResourceKey <Enchantment >, level : Int ): Builder {
129136 effects.add(EnchantmentArmorEffect (enchantment, level))
@@ -140,8 +147,17 @@ object GenerationsArmor: ItemPlatformRegistry() {
140147 return this
141148 }
142149
150+ fun attributeModifier (slot : EquipmentSlotGroup , holder : Holder <Attribute >, id : ResourceLocation , amount : Double , operation : AttributeModifier .Operation ): Builder {
151+ data.computeIfAbsent(slot) { mutableListOf () } + = holder to AttributeModifier (id, amount, operation)
152+ return this
153+ }
154+
143155 fun build (): ArmorSet {
144- return create(name, armormaterial, * effects.toTypedArray())
156+ return create(name, armormaterial, data, * effects.toTypedArray())
157+ }
158+
159+ fun speedAttribute (slot : EquipmentSlotGroup , amount : Double ) {
160+ attributeModifier(slot, Attributes .MOVEMENT_SPEED , " 50_speed" .generationsResource(), amount, AttributeModifier .Operation .ADD_MULTIPLIED_BASE )
145161 }
146162 }
147163
@@ -158,47 +174,62 @@ object GenerationsArmor: ItemPlatformRegistry() {
158174 return Builder (name, armorMaterial)
159175 }
160176
177+
178+
161179 fun create (
162180 name : String ,
163181 armorMaterial : Holder <ArmorMaterial >,
182+ attributeModifiers : Map <EquipmentSlotGroup , List <Pair <Holder <Attribute >, AttributeModifier >>> = mutableMapOf(),
164183 vararg armorEffects : ArmorEffect
165184 ): ArmorSet {
166-
167185 return ArmorSet (
168186 register(
169187 name + " _helmet"
170188 ) { properties: Item .Properties ->
189+ val list = attributeModifiers.getOrDefault(EquipmentSlotGroup .HEAD , listOf ())
190+
171191 GenerationsArmorItem (
172192 armorMaterial,
173193 ArmorItem .Type .HELMET ,
174- properties
194+
195+ properties,
196+ list
175197 )
176198 },
177199 register(
178200 name + " _chestplate"
179201 ) { properties: Item .Properties ->
202+ val list = attributeModifiers.getOrDefault(EquipmentSlotGroup .CHEST , listOf ())
203+
180204 GenerationsArmorItem (
181205 armorMaterial,
182206 ArmorItem .Type .CHESTPLATE ,
183- properties
207+ properties,
208+ list
184209 )
185210 },
186211 register(
187212 name + " _leggings"
188213 ) { properties: Item .Properties ->
214+ val list = attributeModifiers.getOrDefault(EquipmentSlotGroup .LEGS , listOf ())
215+
189216 GenerationsArmorItem (
190217 armorMaterial,
191218 ArmorItem .Type .LEGGINGS ,
192- properties
219+ properties,
220+ list
193221 )
194222 },
195223 register(
196224 name + " _boots"
197225 ) { properties: Item .Properties ->
226+ val list = attributeModifiers.getOrDefault(EquipmentSlotGroup .FEET , listOf ())
227+
198228 GenerationsArmorItem (
199229 armorMaterial,
200230 ArmorItem .Type .BOOTS ,
201231 properties,
232+ list,
202233 * armorEffects
203234 )
204235 },
0 commit comments