Jump to content

[1.7.2] [Unsolved]Problems with shooting entity


knokko

Recommended Posts

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.