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.

Having problems with Custom Item.class onUpdate(), Client/Server syncing

Featured Replies

Posted

Hi, I am trying to use the onUpdate() Method in a custom Item.class to damage other items in the players inventory.

 

Such as...

public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
    {
    		EntityPlayer p = ((EntityPlayer)par3Entity);
    		if (p.isSneaking() == true && p.inventory.hasItem(mod_HarkenScythe.HSSpectralMirror.shiftedIndex))
    		{
Damage other item via Itemstack.damageItem(damageAmount, entityplayer)
}
};

 

The last part is just Pseudo. "I have other Methods linked to it".

 

Now this works all nice like  however if the player logs out of the game or drops the item to the ground (Q key), the Item that was damage regains all of its Durability. I believe this is cause by Client and Server no syncing correctly. (Client Item is taking damage, while the server Item is not).

 

This is very problamatic and I can't seem to find a solution for this oddity T_T.

 

In a nut shell... I believe onUpdate() method is only called by the client and the server ignores it.

 

Any help would be greatly appreciated!

 

Have you tried if(!par2World.isRemote) ???

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Hmm, add a Minecraft.thePlayer.addChatMessage("derp") and check if it out puts the message once or twice when you shift, if once, that means that it's only being called by client and that you should change to cast to EntitPlayerMP, otherwise try adding a tick handler in a proxy so you can check players inventory there.

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

  • Author

Sadly if (!par2World.isRemote) totaly kills the Item.class onUpdate() method. Since only the client is handling it.

 

And as for EntityPlayerMP, the cast just creates errors. Standalone. And doesn't not call any actions if, if (par3Entity instanceof EntityPlayerMP) is used.

 

=/

 

Is there a way to Re-sync Items (client and server) after they take damage from client?

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.