Jump to content

Recommended Posts

Posted

I am trying to change some mobs to "another" mob and i keep getting a ghost mob and the new one. I have used this code before and did not have this problem so i cannot figure this out.

 

here is the code im using:

 

 

private int loc = 0;

public void onLivingUpdate() {
	super.onLivingUpdate();

	if (loc == 0) {
		loc += 1;
		if (Loader.isModLoaded("mochickens")) {
			System.out.println("Creeper Chicken Mob: X=" + this.posX
					+ " Y=" + this.posY + " Z=" + this.posZ
					+ " attempting to change");
			try {
				EntityLiving newEntity = (EntityLiving) EntityCreeperChicken.class
						.getDeclaredConstructor(new Class[] { World.class })
						.newInstance(new Object[] { this.worldObj });
				if (this.isChild()) {
					((EntityAgeable) newEntity).setGrowingAge(this
							.getGrowingAge());
				}
				newEntity.setLocationAndAngles(this.posX, this.posY + 0.5D,
						this.posZ, this.rotationPitch, this.rotationYaw);
				if (this.isTamed()) {
					((EntityCreeperChicken) newEntity).setTamed(true);
					((EntityTameable) newEntity).setOwner(this
							.getOwnerName());
				}
				this.worldObj.spawnEntityInWorld(newEntity);
				this.setDead();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SecurityException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
       }

 

 

 

Could any possibly point out why this is happening?

 

501e729b7ba5277a3224b416db7a1263.png

Posted

ok, thank you. I should have thought of that. its works right now.

 

Working Code:

 

private int loc = 0;

public void onLivingUpdate() {
	super.onLivingUpdate();

	if ((loc == 0) && (!this.worldObj.isRemote)) {
		loc += 1;
		if (Loader.isModLoaded("mochickens")) {
			System.out.println("Creeper Chicken Mob: X=" + this.posX
					+ " Y=" + this.posY + " Z=" + this.posZ
					+ " attempting to change");
			try {
				EntityLiving newEntity = (EntityLiving) EntityCreeperChicken.class
						.getDeclaredConstructor(new Class[] { World.class })
						.newInstance(new Object[] { this.worldObj });
				if (this.isChild()) {
					((EntityAgeable) newEntity).setGrowingAge(this
							.getGrowingAge());
				}
				newEntity.setLocationAndAngles(this.posX, this.posY + 0.5D,
						this.posZ, this.rotationPitch, this.rotationYaw);
				if (this.isTamed()) {
					((EntityCreeperChicken) newEntity).setTamed(true);
					((EntityTameable) newEntity).setOwner(this
							.getOwnerName());
				}
				this.worldObj.spawnEntityInWorld(newEntity);
				this.setDead();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SecurityException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}

 

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.

Announcements



×
×
  • Create New...

Important Information

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