Jump to content

Recommended Posts

Posted

Hi all,

 

I've been having a strange bug: I have an item that overrides the onItemUseFirst method in the base Item class, and because it changes blocks in the minecraft world it has to be called both clientside and serverside. Through testing, I've determined that whenever it returns false, it appears to be invoked both clientside and serverside and works fine (barring the fact it's returning false when it really shouldn't, slightly unusual things happen with levers and buttons) but when it returns true, it is never called serverside at all. 

 

Notes on testing:

 

 

At first, I had the item determine if it modified any blocks, and return true if it did.  This created weird temporary blocks, that disappeared when right-clicked, when water flowed on top of them, and on world save/load.  Adding an if (!world.isRemote) test made the item change blocks correctly, but because of how I tested if it modified blocks caused it to always return false.  Changing the return statement to simply return true, combined with the if (!world.isRemote) on the block-changing code, played the 'item-used-animation' but didn't change any blocks, while changing the return statement to simply return false caused the item to work properly, but there was no 'item-used-animation' and blocks had onBlockActivated code called that I don't really want called.

 

 

 

What exactly causes this to happen? 

Posted

I didn't tried this, but what if you would return true on the client and return false on the server? Like:

 

if(world.isRemote)
    return true;
else
    return false;

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Its down to how MC reports clicking items/blocks. Its really shitty, but basically, you should just return false on the client side, and only do any real processing on the server.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

Its down to how MC reports clicking items/blocks. Its really shitty, but basically, you should just return false on the client side, and only do any real processing on the server.

 

Yeah, I was afraid of that.  So returning true clientside will always prevent calling serverside. . .  Thanks. 

 

One follow-up question, minecraft plays a little animation with whatever item's in the player's hand when left-clicking on a block or right-clicking with certain items in hand -- notably when placing vines and lily-pads in the world (and, prior to 1.3.2, when onItemUse returned true).  Is there any way to play that animation when using my item, instead of the 'default' item-is-rightclicked-on-a-block one?

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.