NaturesAura/src/main/java/de/ellpeck/naturesaura/items/ItemDeathRing.java

45 lines
1.7 KiB
Java
Raw Normal View History

2020-02-07 23:50:16 +01:00
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.packet.PacketClient;
import de.ellpeck.naturesaura.packet.PacketHandler;
import net.minecraft.entity.LivingEntity;
2021-12-04 15:40:09 +01:00
import net.minecraft.entity.player.Player;
2020-02-07 23:50:16 +01:00
import net.minecraft.item.ItemStack;
2021-12-04 15:40:09 +01:00
import net.minecraft.nbt.CompoundTag;
2020-02-07 23:50:16 +01:00
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class ItemDeathRing extends ItemImpl {
public ItemDeathRing() {
super("death_ring", new Properties().maxStackSize(1));
MinecraftForge.EVENT_BUS.register(new Events());
}
public static class Events {
@SubscribeEvent
public void onDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving();
2021-12-04 15:40:09 +01:00
if (!entity.level.isClientSide && entity instanceof Player) {
ItemStack equipped = Helper.getEquippedItem(s -> s.getItem() == ModItems.DEATH_RING, (Player) entity);
2020-02-07 23:50:16 +01:00
if (!equipped.isEmpty()) {
entity.setHealth(entity.getMaxHealth() / 2);
entity.clearActivePotions();
entity.addPotionEffect(new EffectInstance(Effects.REGENERATION, 500, 1));
2021-12-04 15:40:09 +01:00
CompoundTag data = new CompoundTag();
2020-09-22 15:38:58 +02:00
data.putInt("id", entity.getEntityId());
2021-12-04 15:40:09 +01:00
PacketHandler.sendToAllAround(entity.level, entity.getPosition(), 32, new PacketClient(1, data));
2020-02-07 23:50:16 +01:00
equipped.shrink(1);
event.setCanceled(true);
}
}
}
}
}