nike4613 Posted November 16, 2014 Share Posted November 16, 2014 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? Quote Link to comment Share on other sites More sharing options...
coolAlias Posted November 16, 2014 Share Posted November 16, 2014 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. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
nike4613 Posted November 16, 2014 Author Share Posted November 16, 2014 So how do I find the entity server-side? Quote Link to comment Share on other sites More sharing options...
coolAlias Posted November 17, 2014 Share Posted November 17, 2014 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. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
nike4613 Posted November 18, 2014 Author Share Posted November 18, 2014 Could I see a peice of code for server-side? For locating the entity? Quote Link to comment Share on other sites More sharing options...
coolAlias Posted November 18, 2014 Share Posted November 18, 2014 if (!world.isRemote) { // do your thing here } Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
Recommended Posts
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.