Posted October 27, 20159 yr Hey, I have been having this problem for a couple of days. When I try to spawn an entity with my item by clicking the ground, it spawns, but it doesn't move at all, it can't get hurt, it can't be pushed, etc. I think once I waited for a little, and it disappeared (I'm not sure about this though). NOTE: I have tried doing my own research and they all said that I needed to add if (!world.isRemote) in order for it to work. I have tried this, but nothing at all spawns. This is the code I am using: @Override public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if(stack.getItem() == TestItems.test_item) { if (!worldIn.isRemote) { EntityTest test= new EntityTest(worldIn); worldIn.spawnEntityInWorld(test); test.setPosition(pos.getX(), pos.getY() + 1, pos.getZ()); return true; } } return false; } How do I fix this?
October 27, 20159 yr @Override public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { EntityZombie test = new EntityZombie(worldIn); worldIn.spawnEntityInWorld(test); test.setPosition(pos.getX(), pos.getY() + 1, pos.getZ()); return true; } return false; } It is impossible that this doesn't work. (You don't need item check, you are alredy in it, unless you need instance-specific checks). There is probably something wrong with your EntityTest - you might not have renderer for it. Or you messed up constructors? 1.7.10 is no longer supported by forge, you are on your own.
October 27, 20159 yr Author @Override public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { EntityZombie test = new EntityZombie(worldIn); worldIn.spawnEntityInWorld(test); test.setPosition(pos.getX(), pos.getY() + 1, pos.getZ()); return true; } return false; } I actually just tried that code out right now. I still get nothing spawning when I write "!worldIn.isRemote" and I get a "still" zombie when I write "worldIn.isRemote" This is how the zombie looks like when I write "worldIn.isRemote": Notice how the zombie isn't even on fire or reacting to me being that close to it. As for this: There is probably something wrong with your EntityTest - you might not have renderer for it. Or you messed up constructors? I have a renderer for my Entity. I am able to spawn the entity fine with an egg. I just want the player to be able to spawn the entity with an item as I dont want the entity spawning naturally and eggs are basically unattainable in survival.
October 28, 20159 yr I think you are blindly using world.isRemote. A little explanation: http://www.minecraftforge.net/forum/index.php/topic,33918.msg178740.html#msg178740 So yeah - you MUST use !world.isRemote, and that "still zombie" is effect of no doing so - it spawns only on client, so server doesn't know about it, therefore it is kinda "dead". As to problem - I am on 1.8, you are on 1.8. The code I gave you WORKS (that is not theory). Since it works - you did something else wrong. Show me your whole Item class and how you initilize your items. Do you use some forge event that could cancel spawning? Maybe you use interaction events that could cancel clicking? 1.7.10 is no longer supported by forge, you are on your own.
October 28, 20159 yr If you look at any of the vanilla entity spawning code, you will see that you need to call #setLocationAndAngles on the entity BEFORE you spawn it into the world, along with as much other relevant information as you can. The reason being that when you call #spawnEntityInWorld on the server, it sends a spawn packet to the client containing the entity's current information, including location - if that information is lacking, the default values are used. In your case, the entity, lacking any knowledge of its own coordinates at the time it joins the world, spawns on the client at (0, 0, 0), likely very far from where it spawned on the server and nowhere near where you will be able to see it. EDIT: And the 'still' version was, of course, because you spawned it on the client only, which doesn't run any AI logic - basically, it was a ghost, not a real entity. http://i.imgur.com/NdrFdld.png[/img]
October 28, 20159 yr If you look at any of the vanilla entity spawning code, you will see that you need to call #setLocationAndAngles on the entity BEFORE you spawn it into the world, along with as much other relevant information as you can. The reason being that when you call #spawnEntityInWorld on the server, it sends a spawn packet to the client containing the entity's current information, including location - if that information is lacking, the default values are used. In your case, the entity, lacking any knowledge of its own coordinates at the time it joins the world, spawns on the client at (0, 0, 0), likely very far from where it spawned on the server and nowhere near where you will be able to see it. EDIT: And the 'still' version was, of course, because you spawned it on the client only, which doesn't run any AI logic - basically, it was a ghost, not a real entity. Above is right, forgot to write that, but also - it DOES NOT mean that code I provided isn't working (beacuse it is). Therefore - if code I gave you didn't work, then the mistake is elsewhere, setting pos before spawning won't help you. Just saying. Post your other code. 1.7.10 is no longer supported by forge, you are on your own.
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.