Jump to content

[SOLVE] [1.7.10] cannot change pig -> cow


jmylifecolor

Recommended Posts

 @SubscribeEvent//오른쪽 클릭했을때 이벤트
public void onEntityRightClicked(EntityInteractEvent e)
{
	 EntityCow dead;
	 if (e.target instanceof EntityPig)
	 {
		 EntityPig pig = (EntityPig) e.target;
		 double x = pig.posX;
		 double y = pig.posY;
		 double z = pig.posZ;
		 dead = new EntityCow(e.target.worldObj);
		 dead.copyLocationAndAnglesFrom(pig);
		// dead.setPosition(x,y,z);
		 System.out.println(dead.getCommandSenderName() + dead.posX + ","+ dead.posY + "," + dead.posZ);
		 pig.setDead();
	 }
}

why not working my code..?

pig delete working. buy, not create cow entity..

Link to comment
Share on other sites

Please learn more Java.

 

Making "new Cow" != "spawn Cow". You need to call World#spawnEntityInWorld.

 

Clean up useless code, learn to code properly.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

What Ernio was so nicely trying to explain is that creating the new instance of EntityCow simply constructs the data for the cow in memory, but doesn't actually add it to the world to participate in the game. To do that, you need to spawn the cow in the world, and furthermore make sure the position is correct.

 

Note also that you must spawn the cow on the server side, otherwise it creates sort of a "ghost" entity that will look right briefly but then do weird stuff.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

What Ernio was so nicely trying to explain is that creating the new instance of EntityCow simply constructs the data for the cow in memory, but doesn't actually add it to the world to participate in the game. To do that, you need to spawn the cow in the world, and furthermore make sure the position is correct.

 

Note also that you must spawn the cow on the server side, otherwise it creates sort of a "ghost" entity that will look right briefly but then do weird stuff.

 

Oh! Good Answer. This was perfectly understood. Thanks bro.

 

solve as next:

                //param is Server World.

EntityZombie zombie = new EntityZombie( MinecraftServer.getServer().getEntityWorld());

//First server

MinecraftServer.getServer().getEntityWorld().spawnEntityInWorld(zombie);

                //Last Client Create.

e.entityPlayer.getEntityWorld().spawnEntityInWorld(zombie);

Link to comment
Share on other sites

                //param is Server World.

EntityZombie zombie = new EntityZombie( MinecraftServer.getServer().getEntityWorld());

//First server

MinecraftServer.getServer().getEntityWorld().spawnEntityInWorld(zombie);

                //Last Client Create.

e.entityPlayer.getEntityWorld().spawnEntityInWorld(zombie);

Oh god please no.

getServer().getEntityWorld() is always the overworld, not the player's world!

Only spawn it on the server using player#getEntityWorld, you do not need to spawn it on the client separately, minecraft handles that for you.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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