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;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.nbt.CompoundTag;
|
2021-12-15 16:24:53 +01:00
|
|
|
import net.minecraft.world.effect.MobEffectInstance;
|
|
|
|
import net.minecraft.world.effect.MobEffects;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
2020-02-07 23:50:16 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
|
|
|
|
public class ItemDeathRing extends ItemImpl {
|
2021-12-15 16:24:53 +01:00
|
|
|
|
2020-02-07 23:50:16 +01:00
|
|
|
public ItemDeathRing() {
|
2021-12-15 16:24:53 +01:00
|
|
|
super("death_ring", new Properties().stacksTo(1));
|
2020-02-07 23:50:16 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(new Events());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Events {
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onDeath(LivingDeathEvent event) {
|
2022-08-01 16:14:37 +02:00
|
|
|
var entity = event.getEntity();
|
2023-07-08 12:32:27 +02:00
|
|
|
if (!entity.level().isClientSide && entity instanceof Player) {
|
2023-09-19 22:54:09 +02:00
|
|
|
var equipped = Helper.getEquippedItem(s -> s.getItem() == ModItems.DEATH_RING, (Player) entity, false);
|
2020-02-07 23:50:16 +01:00
|
|
|
if (!equipped.isEmpty()) {
|
|
|
|
entity.setHealth(entity.getMaxHealth() / 2);
|
2021-12-15 16:24:53 +01:00
|
|
|
entity.removeAllEffects();
|
|
|
|
entity.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 500, 1));
|
2020-02-07 23:50:16 +01:00
|
|
|
|
2021-12-15 16:30:22 +01:00
|
|
|
var data = new CompoundTag();
|
2021-12-15 16:24:53 +01:00
|
|
|
data.putInt("id", entity.getId());
|
2023-07-08 12:32:27 +02:00
|
|
|
PacketHandler.sendToAllAround(entity.level(), entity.blockPosition(), 32, new PacketClient(1, data));
|
2020-02-07 23:50:16 +01:00
|
|
|
|
|
|
|
equipped.shrink(1);
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-19 22:54:09 +02:00
|
|
|
|
2020-02-07 23:50:16 +01:00
|
|
|
}
|
2023-09-19 22:54:09 +02:00
|
|
|
|
2020-02-07 23:50:16 +01:00
|
|
|
}
|