2018-12-31 17:32:38 +01:00
|
|
|
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;
|
2018-12-31 17:32:38 +01:00
|
|
|
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;
|
2018-12-31 17:32:38 +01:00
|
|
|
|
2020-01-26 01:41:49 +01:00
|
|
|
public class ItemBirthSpirit extends ItemGlowing {
|
|
|
|
public ItemBirthSpirit() {
|
2018-12-31 17:32:38 +01:00
|
|
|
super("birth_spirit");
|
2020-01-24 20:49:09 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
2018-12-31 17:32:38 +01:00
|
|
|
}
|
|
|
|
|
2020-01-24 20:49:09 +01:00
|
|
|
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;
|
2018-12-31 17:32:38 +01:00
|
|
|
|
2020-01-24 20:49:09 +01:00
|
|
|
int amount = parent.world.rand.nextInt(3) + 1;
|
|
|
|
ItemEntity item = new ItemEntity(parent.world, parent.posX, parent.posY, parent.posZ,
|
|
|
|
new ItemStack(ModItems.BIRTH_SPIRIT, amount));
|
|
|
|
parent.world.addEntity(item);
|
2018-12-31 17:32:38 +01:00
|
|
|
|
2020-01-24 20:49:09 +01:00
|
|
|
BlockPos spot = IAuraChunk.getHighestSpot(parent.world, pos, 30, pos);
|
|
|
|
IAuraChunk.getAuraChunk(parent.world, spot).drainAura(spot, 800 * amount);
|
|
|
|
}
|
2018-12-31 17:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|