You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.1 KiB
Java
57 lines
2.1 KiB
Java
// File: SwiftnessHandler.java
|
|
package com.zivilon.cinder_loe;
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraftforge.event.entity.living.LivingEvent;
|
|
import lotr.common.enchant.LOTREnchantment;
|
|
import lotr.common.enchant.LOTREnchantmentHelper;
|
|
import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
|
|
|
import java.util.UUID;
|
|
|
|
public class SwiftnessHandler {
|
|
// Use fixed UUIDs to prevent stacking
|
|
private static final UUID[] SWIFTNESS_UUIDS = new UUID[]{
|
|
UUID.fromString("123e4567-e89b-12d3-a456-426614174001"), // boots
|
|
UUID.fromString("123e4567-e89b-12d3-a456-426614174002"), // leggings
|
|
UUID.fromString("123e4567-e89b-12d3-a456-426614174003"), // chestplate
|
|
UUID.fromString("123e4567-e89b-12d3-a456-426614174004") // helmet
|
|
};
|
|
private static final String[] MODIFIER_NAMES = new String[]{
|
|
"SwiftnessBoots", "SwiftnessLegs", "SwiftnessChest", "SwiftnessHelm"
|
|
};
|
|
|
|
@SubscribeEvent
|
|
public void onPlayerTick(LivingEvent.LivingUpdateEvent event) {
|
|
if (!(event.entityLiving instanceof EntityPlayer)) return;
|
|
|
|
EntityPlayer player = (EntityPlayer) event.entityLiving;
|
|
|
|
for (int i = 0; i < player.inventory.armorInventory.length; i++) {
|
|
ItemStack armor = player.inventory.armorInventory[i];
|
|
UUID uuid = SWIFTNESS_UUIDS[i];
|
|
String label = MODIFIER_NAMES[i];
|
|
|
|
// Get movement speed attribute
|
|
IAttributeInstance attr = player.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
|
|
AttributeModifier existingMod = attr.getModifier(uuid);
|
|
|
|
if (armor != null && LOTREnchantmentHelper.hasEnchant(armor, LOTREnchantment.getEnchantmentByName("swiftness"))) {
|
|
if (existingMod == null) {
|
|
AttributeModifier mod = new AttributeModifier(uuid, label, 0.05, 1);
|
|
attr.applyModifier(mod);
|
|
}
|
|
} else {
|
|
if (existingMod != null) {
|
|
attr.removeModifier(existingMod);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|