Jump to content

[1.7.10] Server sync issue? entity.setPosition not working


Recommended Posts

Posted

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?

Posted

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.

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.