Posted November 16, 201410 yr Code: public ItemStack onItemRightClick(ItemStack is, World w, EntityPlayer p) { Minecraft mc = Minecraft.getMinecraft(); MovingObjectPosition target = mc.objectMouseOver; double i = mc.renderViewEntity.posX; double j = mc.renderViewEntity.posY; double k = mc.renderViewEntity.posZ; float r = 3; if(target != null) { if(target.entityHit != null) { target.entityHit.setPosition(i, j, k); p.addChatMessage(new ChatComponentText("[Telekinesis->Wand] Found and Teleported Entity").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN))); }else p.addChatMessage(new ChatComponentText("[Telekinesis->Wand] Did not find entity").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); } p.addChatMessage(new ChatComponentText("[Telekinesis->Wand] Item Right-Click Successful").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN))); return is; } When I use the item and all text is green, the entity moves, and then "unmoves", moves back to its original location. How do I fix it? And is it a server sync issue?
November 16, 201410 yr It's because you are using client-side logic (Minecraft.getMinecraft(), mouseover, etc.) to place the entity, so you are only placing it on the client side; during the next tick, the server tells the entity "hey, that's not where you are" and moves the entity back. You need to set the position on the server, i.e. when world.isRemote returns false, and figure out how to determine a MovingObjectPosition without objectmouseover. Or you could handle the logic client side and send a packet, but that is more work. http://i.imgur.com/NdrFdld.png[/img]
November 17, 201410 yr Use the player's look vector and either one of World's raytracing methods or iterate manually over the vector until you hit something. I'm sure there are plenty of solutions on this forum if you search. http://i.imgur.com/NdrFdld.png[/img]
November 18, 201410 yr if (!world.isRemote) { // do your thing here } http://i.imgur.com/NdrFdld.png[/img]
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.