Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.