diff --git a/src/main/java/com/majruszs_difficulty/RegistryHandler.java b/src/main/java/com/majruszs_difficulty/RegistryHandler.java index 5800f6033..7f3afcba6 100644 --- a/src/main/java/com/majruszs_difficulty/RegistryHandler.java +++ b/src/main/java/com/majruszs_difficulty/RegistryHandler.java @@ -8,6 +8,7 @@ import com.majruszs_difficulty.features.undead_army.ReloadUndeadArmyGoals; import com.majruszs_difficulty.features.undead_army.UndeadArmyManager; import com.majruszs_difficulty.generation.OreGeneration; +import com.majruszs_difficulty.items.AttributeArmorItem; import com.majruszs_difficulty.items.FakeItem; import com.mlib.items.SpawnEggFactory; import com.mojang.brigadier.CommandDispatcher; @@ -240,6 +241,8 @@ private static void setup( final FMLCommonSetupEvent event ) { event.enqueueWork( Instances.FLYING_END_ISLAND::setup ); event.enqueueWork( Instances.FLYING_END_SHIP::setup ); OreGeneration.registerOres(); + + AttributeArmorItem.updateAllItemsAttributes(); } /** Registration of commands. */ diff --git a/src/main/java/com/majruszs_difficulty/items/HermesBootsItem.java b/src/main/java/com/majruszs_difficulty/items/HermesBootsItem.java index 2e2f4334f..3dd90d4d4 100644 --- a/src/main/java/com/majruszs_difficulty/items/HermesBootsItem.java +++ b/src/main/java/com/majruszs_difficulty/items/HermesBootsItem.java @@ -1,63 +1,46 @@ package com.majruszs_difficulty.items; +import com.google.common.collect.ImmutableMultimap; import com.majruszs_difficulty.Instances; import com.majruszs_difficulty.MajruszsDifficulty; -import com.majruszs_difficulty.MajruszsHelper; import com.majruszs_difficulty.models.HermesArmorModel; -import com.mlib.attributes.AttributeHandler; import com.mlib.config.ConfigGroup; import com.mlib.config.DoubleConfig; import net.minecraft.client.renderer.entity.model.BipedModel; -import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.attributes.Attribute; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.item.ArmorItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Rarity; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import javax.annotation.Nullable; -import java.util.List; +import java.util.UUID; /** Boots that increases movement speed. */ @Mod.EventBusSubscriber -public class HermesBootsItem extends ArmorItem { - protected static final AttributeHandler MOVEMENT_BONUS_ATTRIBUTE = new AttributeHandler( "dbe472cb-df52-44ab-ab38-01b00e24f649", - "HermesBootsMovementSpeedBonus", Attributes.MOVEMENT_SPEED, AttributeModifier.Operation.MULTIPLY_BASE - ); +public class HermesBootsItem extends AttributeArmorItem { protected final DoubleConfig movementSpeedBonus; protected final ConfigGroup configGroup; - private static final String TOOLTIP_TRANSLATION_KEY = "item.majruszs_difficulty.hermes_boots.item_tooltip"; public HermesBootsItem() { super( CustomArmorMaterial.HERMES, EquipmentSlotType.FEET, ( new Properties() ).group( Instances.ITEM_GROUP ) .rarity( Rarity.UNCOMMON ) ); - String comment = "Movement speed extra multiplier."; - this.movementSpeedBonus = new DoubleConfig( "movement_speed_bonus", comment, false, 0.25, 0.0, 1.0 ); + String comment = "Movement speed extra multiplier. (requires game/world restart!)"; + this.movementSpeedBonus = new DoubleConfig( "movement_speed_bonus", comment, true, 0.25, 0.0, 5.0 ); this.configGroup = new ConfigGroup( "HermesBoots", "Hermes Boots item configuration." ); MajruszsDifficulty.FEATURES_GROUP.addGroup( this.configGroup ); this.configGroup.addConfig( this.movementSpeedBonus ); } - /** Adds tooltip about Hermes Boots movement speed bonus. */ - @Override - @OnlyIn( Dist.CLIENT ) - public void addInformation( ItemStack itemStack, @Nullable World world, List< ITextComponent > tooltip, ITooltipFlag flag ) { - MajruszsHelper.addAdvancedTooltip( tooltip, flag, TOOLTIP_TRANSLATION_KEY ); - } - /** Returns path to Hermes Boots texture. */ @Nullable @Override @@ -92,17 +75,13 @@ public String getArmorTexture( ItemStack stack, Entity entity, EquipmentSlotType return ( ArmorModel )model; } - @SubscribeEvent - public static void onEquipmentChange( LivingEquipmentChangeEvent event ) { - LivingEntity entity = event.getEntityLiving(); - - MOVEMENT_BONUS_ATTRIBUTE.setValue( Instances.HERMES_BOOTS_ITEM.getMovementSpeedBonus( entity ) ) - .apply( entity ); - } - - /** Returns movement speed bonus if entity has Hermes Boots equipped. */ - public double getMovementSpeedBonus( LivingEntity entity ) { - ItemStack boots = entity.getItemStackFromSlot( EquipmentSlotType.FEET ); - return ( boots.getItem() instanceof HermesBootsItem ? 1.0 : 0.0 ) * this.movementSpeedBonus.get(); + /** Called whenever attributes should be updated. */ + @Override + protected void updateAttributes( ImmutableMultimap.Builder< Attribute, AttributeModifier > builder ) { + builder.put( Attributes.MOVEMENT_SPEED, + new AttributeModifier( UUID.fromString( "dbe472cb-df52-44ab-ab38-01b00e24f649" ), "HermesBootsMovementSpeedBonus", + this.movementSpeedBonus.get(), AttributeModifier.Operation.MULTIPLY_BASE + ) + ); } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 9a36cb36a..cd5c732bc 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -6,5 +6,6 @@ public-f net.minecraft.world.biome.BiomeGenerationSettings field_242485_g public net.minecraft.potion.EffectInstance showParticles public-f net.minecraft.entity.monster.CreeperEntity field_82226_g # explosionRadius protected-f net.minecraft.entity.monster.AbstractSkeletonEntity field_85037_d # aiArrowAttack +protected-f net.minecraft.item.ArmorItem field_234656_m_ # attributes # public net.minecraft.world.gen.feature.structure.Structure field_236385_u_ # public-f net.minecraft.world.gen.feature.structure.Structure field_236384_t_ \ No newline at end of file diff --git a/src/main/resources/assets/majruszs_difficulty/lang/en_us.json b/src/main/resources/assets/majruszs_difficulty/lang/en_us.json index 6e1824c81..5c7db911d 100644 --- a/src/main/resources/assets/majruszs_difficulty/lang/en_us.json +++ b/src/main/resources/assets/majruszs_difficulty/lang/en_us.json @@ -28,7 +28,6 @@ "item.majruszs_difficulty.bandage.item_tooltip1": "Removes bleeding from the target.", "item.majruszs_difficulty.bandage.item_tooltip2": "It can be used on yourself and on other mobs.", "item.majruszs_difficulty.hermes_boots": "Hermes Boots", - "item.majruszs_difficulty.hermes_boots.item_tooltip": "Increases moving speed when worn.", "item.majruszs_difficulty.end_shard": "End Shard", "item.majruszs_difficulty.end_ingot": "End Ingot", "item.majruszs_difficulty.end_sword": "End Sword",