Posted August 10, 201312 yr Hello community. I am trying to check if a certain player is around, and if so, then spawn a lightning bolt on the coordinates of the EntityCreeper. This is what I have right now. package test.proxies; import java.util.EnumSet; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.monster.EntityCreeper; import net.minecraft.entity.player.EntityPlayer; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; public class ServerTickHandler implements ITickHandler { private void onPlayerTick(EntityPlayer player){ EntityCreeper target = new EntityCreeper(player.worldObj); chargeCreepers(player, target); } private void chargeCreepers(EntityPlayer player, EntityCreeper target) { if(Math.abs(target.posX - player.posX) < 20 && Math.abs(target.posZ - player.posZ) < 20 && target.canEntityBeSeen(player)){ player.worldObj.spawnEntityInWorld(new EntityLightningBolt(player.worldObj, target.posX, target.posY, target.posZ)); } } @Override public void tickStart(EnumSet<TickType> type, Object... tickData) { if(type.equals(EnumSet.of(TickType.PLAYER))){ onPlayerTick((EntityPlayer) tickData[0]); } } @Override public void tickEnd(EnumSet<TickType> type, Object... tickData) { // TODO Auto-generated method stub } @Override public EnumSet<TickType> ticks() { return EnumSet.of(TickType.PLAYER, TickType.SERVER); } @Override public String getLabel() { // TODO Auto-generated method stub return null; } } There is probably some elementary mistake I am overlooking.
August 10, 201312 yr You're making a new instance of EntityCreeper, instead of retrieving an existing one in the world. Use World.getEntitiesWithinAABB() to retrieve entitities of a certain type from a certain bounding box. Look at MobSpawnerBaseLogic to see it in action. There it's used to determine if there are too many entities of the spawned entity for the mob spawner to not spawn anymore. When you'll use the right AABB, you can also throw away the distance check (unless you want a spherical range). Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.