Jump to content

[1.7.10] modifying NBT in onUSingTIck prevents onPlayerStoppedUsing being called


Eroc33

Recommended Posts

Is this a bug or is there some reason that writing NBT data changes how right mouse up is handled, or am I doing something different wrong?

Also by adding some simple logging and using @SubscribeEvent that the PlayerUseItemEvent.Stop event isn't always triggered when the use button is released if NBT data is written.

Example code snippet:

public class ItemRFBlaster {
    //some methods ommited for brevity
    @Override
    public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityPlayer entityPlayer, int itemInUseCount)
    {
        super.onPlayerStoppedUsing(itemstack,world,entityPlayer,itemInUseCount);
        logger.info("Stopped using");
        if(getFiremode(itemstack) == Firemode.Single) {
            tryFire(itemstack, world, entityPlayer, itemInUseCount);
        }
        setCoolingdown(itemstack);
        setPartialTicks(itemstack, 0);
    }

    @Override
    public void onUsingTick(ItemStack stack, EntityPlayer player, int count) {
        super.onUsingTick(stack, player, count);
        logger.info("count: {}",count);
        if(player.getEntityWorld().isRemote)
            return;
        assert(player.isUsingItem());
        if(!canFire(stack)) {
            setCoolingdown(stack);
            return;
        }
        if(getFiremode(stack) == Firemode.Auto){
            tryFire(stack,player.getEntityWorld(),player,count);
        }else if(getFiremode(stack) == Firemode.Burst){
            if(tryFire(stack,player.getEntityWorld(),player,count)) {
                incrBurst(stack);
            }
        }
    }

    @Override
    public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityPlayer)
    {
        if(entityPlayer.isSneaking())
        {
            if(!world.isRemote) {
                cycleFiremode(itemstack, entityPlayer);
            }
        }
        else if (entityPlayer.capabilities.isCreativeMode || getEnergyStored(itemstack) >= 5)
        {
            entityPlayer.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
        }

        return itemstack;
    }
    
}

 

Where tryFire, incrBurst, and canFire read and write NBT data.

If the NBT data writing is commented out then onPlayerStoppedUsing is always called when I expect it.

Link to comment
Share on other sites

Writing to the NBT causes Minecraft to believe that the item stack is a new item stack and therefore interrupts any in-use actions.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I don't have enough of your code to know what you're doing with the NBT.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It would be best not to change NBT data while the item is in use, e.g. by using a nextWorldTime for your cooldown instead of an actual counter.

 

That said, it looks like you are also doing other things with the NBT which you may not be able to get away from. You could try setting the item back in use after the NBT is set, but it may still interrupt the action, particularly on the client-side when the new ItemStack is set.

 

If the above doesn't work, you're going to have to come up with an alternate storage method such as using IExtendedEntityProperties to store data about the current item in use, update THAT data each tick instead of actually updating the item, and then (if you still need the data stored on the ItemStack, that is) write that data back to the item when #onPlayerStoppedUsing is called. It's a somewhat cumbersome workaround, but I can vouch for its effectiveness.

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

    • On a private server, the blocks from the mentioned mods (Tinkers construct, Immersive engineering, Create) are swapped with other blocks from those mods. This occurred after updating the server's mods. The problem only applies to me and multiple other players don't have the same issue I do.  I have a link to an unlisted YouTube video from my perspective below. https://youtu.be/bBcsQjFmseg Thanks for any help
    • FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':processResources'. > Could not copy file 'C:\Users\jedil\Downloads\forge-1.20-46.0.14-mdk\src\main\resources\META-INF\mods.toml' to 'C:\Users\jedil\Downloads\forge-1.20-46.0.14-mdk\build\resources\main\META-INF\mods.toml'.    > Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:      SimpleTemplateScript1.groovy: 1: Unexpected input: '(' @ line 1, column 10.         out.print("""# This is an example mods.toml file. It contains the data relating to the loading mods.                  ^   This is my mods.toml script: # This is an example mods.toml file. It contains the data relating to the loading mods. # There are several mandatory fields (#mandatory), and many more that are optional (#optional). # The overall format is standard TOML format, v0.5.0. # Note that there are a couple of TOML lists in this file. # Find more information on toml format here: https://github.com/toml-lang/toml # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml modLoader="javafml" #mandatory # A version range to match for said mod loader - for regular FML @Mod it will be the forge version loaderVersion="${46.0.14}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. # The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. # Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. license="${All Rights Reserved}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod modId="${MCRefined}" #mandatory # The version number of the mod version="${1.0.0}" #mandatory # A display name for the mod displayName="${Minecraft Refined}" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ #updateJSONURL="https://change.me.example.invalid/updates.json" #optional # A URL for the "homepage" for this mod, displayed in the mod UI #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional # A file name (in the root of the mod JAR) containing a logo for display #logoFile="examplemod.png" #optional # A text field displayed in the mod UI #credits="" #optional # A text field displayed in the mod UI authors="${me}" #optional # Display Test controls the display for your mod in the server connection screen # MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. # IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. # IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component. # NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value. # IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself. #displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) # The description text for the mod (multi line!) (#mandatory) description='''${Minecraft, but it's, like, better.}''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. I tried using --scan or --stacktrace, those were no help. I also tried Ctrl+Alt+S, the template I used did not appear. HELP
    • is usual than the imported classes changes in name and int path from version to version   are you sure the code you are putting is for the version you are trying to run 
    • i guest is the word "models/" in the json pathname abrasmagics:models/item/ingot_test.json       {       "parent": "mercmod:item/parent/ingots/parent_ingot_model",       "textures": {         "layer0": "mercmod:item/surface/acero-clear",         "particle": "mercmod:item/surface/acero-clear"       }     }
    • Another crash report need help https://pastebin.com/CQxPs1p2
  • Topics

×
×
  • Create New...

Important Information

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