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

39 lines
1.5 KiB
Java
Raw Normal View History

package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
2019-10-20 22:30:49 +02:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.BabyEntitySpawnEvent;
2019-10-20 22:30:49 +02:00
import net.minecraftforge.eventbus.api.SubscribeEvent;
2020-01-26 01:41:49 +01:00
public class ItemBirthSpirit extends ItemGlowing {
public ItemBirthSpirit() {
super("birth_spirit");
MinecraftForge.EVENT_BUS.register(new EventHandler());
}
private static class EventHandler {
@SubscribeEvent
public void onBabyBorn(BabyEntitySpawnEvent event) {
LivingEntity parent = event.getParentA();
if (!parent.world.isRemote && event.getCausedByPlayer() != null) {
BlockPos pos = parent.getPosition();
int aura = IAuraChunk.getAuraInArea(parent.world, pos, 30);
if (aura < 1200000)
return;
int amount = parent.world.rand.nextInt(3) + 1;
2020-01-28 18:08:56 +01:00
ItemEntity item = new ItemEntity(parent.world, parent.getPosX(), parent.getPosY(), parent.getPosZ(),
new ItemStack(ModItems.BIRTH_SPIRIT, amount));
parent.world.addEntity(item);
BlockPos spot = IAuraChunk.getHighestSpot(parent.world, pos, 30, pos);
IAuraChunk.getAuraChunk(parent.world, spot).drainAura(spot, 800 * amount);
}
}
}
}