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
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
public class BirthSpirit extends Glowing {
|
|
|
|
public BirthSpirit() {
|
2018-12-31 17:32:38 +01:00
|
|
|
super("birth_spirit");
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onBabyBorn(BabyEntitySpawnEvent event) {
|
2019-10-20 22:30:49 +02:00
|
|
|
LivingEntity parent = event.getParentA();
|
2018-12-31 17:32:38 +01:00
|
|
|
if (!parent.world.isRemote && event.getCausedByPlayer() != null) {
|
|
|
|
BlockPos pos = parent.getPosition();
|
|
|
|
int aura = IAuraChunk.getAuraInArea(parent.world, pos, 30);
|
2019-02-03 22:05:56 +01:00
|
|
|
if (aura < 1200000)
|
2018-12-31 17:32:38 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
int amount = parent.world.rand.nextInt(3) + 1;
|
2019-10-20 22:30:49 +02:00
|
|
|
ItemEntity item = new ItemEntity(parent.world, parent.posX, parent.posY, parent.posZ,
|
2018-12-31 17:32:38 +01:00
|
|
|
new ItemStack(ModItems.BIRTH_SPIRIT, amount));
|
2019-11-04 19:08:49 +01:00
|
|
|
parent.world.addEntity(item);
|
2018-12-31 17:32:38 +01:00
|
|
|
|
|
|
|
BlockPos spot = IAuraChunk.getHighestSpot(parent.world, pos, 30, pos);
|
2019-01-29 11:46:38 +01:00
|
|
|
IAuraChunk.getAuraChunk(parent.world, spot).drainAura(spot, 800 * amount);
|
2018-12-31 17:32:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|