Jump to content

Recommended Posts

Posted

I have literally just spent the last two hours on Google and in the source trying to figure this out. I have waded through Packets left and right. I cannot figure out where in the code the player's inventory is synched, and right now, any changes to ItemStack instances or calls to addItemStackToInventory and dropPlayerItem just result in a client-visible update that disappears as soon as the inventory is changed again by vanilla code (like throwing an item or picking up a stack).

But looking at SlotCrafting, that's all it does!

ItemStack var4 = var3.getItem().getContainerItemStack(var3);

 

                    if (!var3.getItem().doesContainerItemLeaveCraftingGrid(var3) || !this.thePlayer.inventory.addItemStackToInventory(var4))

                    {

                        if (this.craftMatrix.getStackInSlot(var2) == null)

                        {

                            this.craftMatrix.setInventorySlotContents(var2, var4);

                        }

                        else

                        {

                            this.thePlayer.dropPlayerItem(var4);

                        }

                    }

That's what it does, for example, when you use milk buckets to craft a cake. Why when I use addItemStackToInventory and dropPlayerItem does it not sync, but when SlotCrafting uses them it does sync? Where is it synching!? :-(

Posted

@Override

    public boolean onItemUseFirst ( ItemStack Item , EntityPlayer Player , World World , int X , int Y , int Z , int Side , float HitX , float HitY , float HitZ )

    {

        int Target = World . getBlockId ( X , Y , Z ) ;

 

        if ( Target == Block . stone . blockID )

        {

            Item . stackSize -- ;

 

            PlayerUtil . Give ( Player , new ItemStack ( net.minecraft.src.Item . stick , 32 ) ) ;

 

            return ( true ) ;

        }

 

        return ( false ) ;

    }


 


    public static void Give ( EntityPlayer Player , ItemStack Stack )

    {

        ( new RuntimeException ( "" + ( Player instanceof net.minecraft.src.EntityPlayerMP ) ) ) . printStackTrace ( ) ;

        if ( ! Player . inventory . addItemStackToInventory ( Stack ) )

        {

            Player . dropPlayerItem ( Stack ) ;

        }

    }

According to that diagnostic printout, whether on the integrated or dedicated server, the onItemUseFirst function is being called only client-side, which I do not understand, because ItemBucket has a right-click function that uses these same functions but synchs up just fine. (Well, mostly fine, but it's always right server-side and only a few display issues client-side now and then, as usual for Minecraft.)

I understand that I could send a packet to the server to initiate the right-click function server-side, but not only is that more work than -should- be required (including the issue of then having to re-sync client-side), there's no reason I can see for it to be necessary.

Posted

Well, I'm going to call this a Forge bug because of the way they changed the function, because if I return false instead of true, meaning continue processing and attempt to activate the block, then the inventory synchs fine.

Honestly, I can't be assed to even try to report this to the Forge people, because they just don't seem that receptive. I'm just going to leave it with sub-optimal behavior and call it a day.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...