fixed armor events being registered a billion times

This commit is contained in:
Ell 2020-10-17 23:13:20 +02:00
parent 557d158c93
commit a24831320d

View file

@ -21,6 +21,7 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -35,7 +36,6 @@ public class ItemArmor extends ArmorItem implements IModItem {
public ItemArmor(String baseName, IArmorMaterial materialIn, EquipmentSlotType equipmentSlotIn) { public ItemArmor(String baseName, IArmorMaterial materialIn, EquipmentSlotType equipmentSlotIn) {
super(materialIn, equipmentSlotIn, new Properties().group(NaturesAura.CREATIVE_TAB)); super(materialIn, equipmentSlotIn, new Properties().group(NaturesAura.CREATIVE_TAB));
this.baseName = baseName; this.baseName = baseName;
MinecraftForge.EVENT_BUS.register(new EventHandler());
ModRegistry.add(this); ModRegistry.add(this);
} }
@ -64,10 +64,11 @@ public class ItemArmor extends ArmorItem implements IModItem {
return Helper.makeRechargeProvider(stack, false); return Helper.makeRechargeProvider(stack, false);
} }
private static class EventHandler { @Mod.EventBusSubscriber
private static final class EventHandler {
@SubscribeEvent @SubscribeEvent
public void onAttack(LivingAttackEvent event) { public static void onAttack(LivingAttackEvent event) {
LivingEntity entity = event.getEntityLiving(); LivingEntity entity = event.getEntityLiving();
if (!entity.world.isRemote) { if (!entity.world.isRemote) {
if (!isFullSetEquipped(entity, ModArmorMaterial.INFUSED)) if (!isFullSetEquipped(entity, ModArmorMaterial.INFUSED))
@ -79,7 +80,7 @@ public class ItemArmor extends ArmorItem implements IModItem {
} }
@SubscribeEvent @SubscribeEvent
public void update(TickEvent.PlayerTickEvent event) { public static void update(TickEvent.PlayerTickEvent event) {
PlayerEntity player = event.player; PlayerEntity player = event.player;
ModifiableAttributeInstance speed = player.getAttribute(Attributes.MOVEMENT_SPEED); ModifiableAttributeInstance speed = player.getAttribute(Attributes.MOVEMENT_SPEED);
String key = NaturesAura.MOD_ID + ":sky_equipped"; String key = NaturesAura.MOD_ID + ":sky_equipped";