Skip to content

Commit

Permalink
Updated Hermes Boots to the new AttributeArmorItem class
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Jun 29, 2021
1 parent c9af7ba commit 2e6595d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 36 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/majruszs_difficulty/RegistryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
49 changes: 14 additions & 35 deletions src/main/java/com/majruszs_difficulty/items/HermesBootsItem.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)
);
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2e6595d

Please sign in to comment.