Posted August 20, 201411 yr hello guys, I was making an entity that has to shoot on passing mobs. But I have 2 problems now. problem 1: My entity disappears when I leave the world. problem 2: The entity shoot always and ignores my mob checker. here is the whole class: public class EntityTowerGun extends Entity{ private String side; public EntityTowerGun(World world, double x, double y, double z, String side) { super(world); setSize(1.0F, 1.0F); posX = x; posY = y; posZ = z; this.side = side; } public void onUpdate(){ super.onUpdate(); this.lookForTarget(); } private void lookForTarget() { //north = negative Z //south = positive Z //west = negative X //east = positive X if(side == "north" && this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(posX - 5, posY - 3, posZ - 2, posX -1, posY - 1, posZ + 2)) != null){ this.worldObj.spawnEntityInWorld(new EntityGunBullet(this.worldObj, posX - 1, posY, posZ, posX - 3, posY - 3, posZ)); } if(side == "south" && this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(posX + 5, posY - 3, posZ - 2, posX + 1, posY - 1, posZ + 2)) != null){ this.worldObj.spawnEntityInWorld(new EntityGunBullet(this.worldObj, posX + 1, posY, posZ, posX + 3, posY - 3, posZ)); } } @Override protected void entityInit() { } @Override protected void readEntityFromNBT(NBTTagCompound var1) { super.readFromNBT(var1); } @Override protected void writeEntityToNBT(NBTTagCompound var1) { super.writeToNBT(var1); } } And here is the part where it checks for mobs, (but is shoot always...): if(side == "north" && this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(posX - 5, posY - 3, posZ - 2, posX -1, posY - 1, posZ + 2)) != null){ this.worldObj.spawnEntityInWorld(new EntityGunBullet(this.worldObj, posX - 1, posY, posZ, posX - 3, posY - 3, posZ)); } if(side == "south" && this.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox(posX + 5, posY - 3, posZ - 2, posX + 1, posY - 1, posZ + 2)) != null){ this.worldObj.spawnEntityInWorld(new EntityGunBullet(this.worldObj, posX + 1, posY, posZ, posX + 3, posY - 3, posZ)); } The east and west sides are not finished yet. Does anybody understand why it ignores the check? I have no errors by the way.
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.