Jump to content

[Mod development] onItemUseFirst: returning true prevents calling serverside


Recommended Posts

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? 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Turning the Tables: My Journey to Reclaim Stolen Bitcoins with Expert Help. When my Bitcoin wallet was hacked and my entire cryptocurrency portfolio was stolen, I felt utterly devastated and hopeless. Having worked hard to build up my digital assets, the sudden loss was gut-wrenching. It felt like my financial future had been ripped away in an instant, leaving me overwhelmed by a sense of betrayal and despair. In my search for help, I discovered TECH CYBER FORCE Recovery, a renowned cybersecurity firm specializing in cryptocurrency recovery. I was met with professionalism and empathy from my first contact with them. The team demonstrated a steadfast commitment to helping me retrieve my stolen Bitcoins. They understood the emotional toll of my situation and approached my case with genuine concern. TECH CYBER FORCE Recovery swung into action immediately, leveraging its extensive expertise in blockchain forensics and hacker tracking techniques. Their process was meticulous. They analyzed my transaction history, followed the digital trail left by the hackers, and worked diligently to pinpoint the location of the stolen funds. I was impressed by their technical prowess; they employed advanced cryptographic methods and strategic negotiations with the perpetrators, all while keeping me informed about their progress. The recovery process was complex and fraught with challenges. However, the tenacity displayed by the team was truly awe-inspiring. They navigated cryptocurrency crime's murky and ever-evolving landscape with skill and determination. After a series of strategic moves, they managed to recover the majority of my Bitcoins successfully.  
    • I removed giacomos_hud, oculus, (dont know what you mean with iris), enhanced_boss_bars, epicfight and essential.  Server still doesnt want to boot. new logs after removing: https://pastebin.com/LuM2PFtN I dont quite understand the "server side" and "client side" difference..
    • There are client side only mods in your server files   Remove giacomos_hud, oculus, iris, enhanced_boss_bars and epicfight You can keep these mods in your client Maybe also remove essentials
    • Here is my Log with java 17: https://pastebin.com/RPdWSjwq
    • Been working on creating a server for this mod, but i keep getting this error over and over again.  I have tried updating/changing the Forge launcher, Removing/replacing the ops.json and whitelist.json folders, and removing certain mods. Crash report log: https://pastebin.com/Bu046cVq Debug.log https://pastebin.com/7hKm40ke Latest.log https://pastebin.com/nCRLUH3b any help would be great thanks!
  • Topics

×
×
  • Create New...

Important Information

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