Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.