Jump to content

Recommended Posts

Posted

I currently have a custom inventory that has two problems:

  • Client side doesn't allow items to enter the custom slots (as it should), but server side allows items to enter the slots
  • Opening the custom inventory will move items around and sometimes dupe things as well.

I think the second problem is possibly coming from how I add the slots are being added in the container, but I'm not exactly sure why beyond that.

 

Container class

  Reveal hidden contents

  

Capability Instance Class

  Reveal hidden contents

 

The transferStackInSlot method is screwed up, but I'll try to fix it after I get these two pretty serious problems out of the way

Posted
  On 5/26/2020 at 8:13 PM, Nozzomi said:

publicpublic ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
        if(stack.getItem() instanceof MythusCore)
            return super.insertItem(slot, stack, simulate);
        else
            return ItemStack.EMPTY;
    }

Expand  

So, if it is the wrong item, destroy it?

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.

Posted

@Draco18s Oops right, I think I just put that there just to see if checking for the right item there would stop server side from allowing it into the slot

Posted

I open the gui in the container by using ClientTickEvent

  Reveal hidden contents

Then in the packet I just use the NetworkHooks#openGui

  Reveal hidden contents

 

 

And uhhh, I just register the container type using the DeferredRegister

public static final RegistryObject<ContainerType<CoreStorageContainer>> CORE_STORAGE_CONTAINER = CONTAINERS.register("core_storage_container",
            () -> new ContainerType<CoreStorageContainer>((id, inv) -> new CoreStorageContainer(id, inv, new CoreStorageInstance())));

 

Posted
  On 5/26/2020 at 9:15 PM, diesieben07 said:

You're given a PlayerInventory, which has the PlayerEntity.

Expand  

I tried using the capability, but the result is the same. The inventory is saving properly though, but so at least that's not a problem.

 

This is what I have now instead

public static final RegistryObject<ContainerType<CoreStorageContainer>> CORE_STORAGE_CONTAINER = CONTAINERS.register("core_storage_container",
            () -> new ContainerType<>((id, inv) -> new CoreStorageContainer(id, inv, inv.player.getCapability(CapabilityCoreStorage.CORE_STORAGE_CAPABILITY).orElse(new CoreStorageInstance()))));

 

Posted
  On 5/28/2020 at 3:06 PM, diesieben07 said:

Both your IItemHandler and your slot (the latter unnecessarily, because the item handler already does it) check for instanceof MythusCore. An item with that class is never created. Thus, nothing can ever be put in the slots (client or server side).

I was not able to reproduce any duping or moving of items in the survival inventory that's shown below. I was not able to put any items into the upper slots (for the reason explained above).

 

Please clarify what your issue is and how to reproduce it.

Expand  

Here's a video of me showing what I'm having problems with.

 

First, I'm showing the clicking the item into the slot that's doesn't allow it, then opening and closing that inventory, where the item ends up in the slot. After that, I'm switching between the vanilla inventory and the custom inventory quickly and the items eventually start to pile up in my inventory. 

 

Posted

That usually happens when you screw up your slot indexes.

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.

Posted
  On 5/28/2020 at 4:21 PM, Draco18s said:

That usually happens when you screw up your slot indexes.

Expand  
for (int i = 0; i < 3; ++i)
{
    for (int j = 0; j < 9; ++j)
    {
        Mythus.LOG.info(j + i * 9 + 9);
        this.addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 132 + i * 18));
    }
}

for (int i = 0; i < 9; ++i)
{
        Mythus.LOG.info(i);
        this.addSlot(new Slot(inventory, i, 8 + i * 18, 190));
}

What would be wrong with this? No numbers are repeating in the logs I think

Posted

Those aren't your only slots, are they.

 

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.

Posted
  On 5/28/2020 at 5:11 PM, Draco18s said:

Those aren't your only slots, are they.

 

Expand  

No, they aren't

for(int i = 0; i < cores.getSlots(); i++)
{
    this.addSlot(new SlotItemHandler(cores, i, slotCoords.get(i).left, slotCoords.get(i).right));
}

I didn't think that they'd affect the player inventory because they're using the indices for a different IItemHandler...it seems I might be wrong though...?

Posted
  On 5/28/2020 at 5:13 PM, Nozzomi said:

No, they aren't

for(int i = 0; i < cores.getSlots(); i++)
{
    this.addSlot(new SlotItemHandler(cores, i, slotCoords.get(i).left, slotCoords.get(i).right));
}

I didn't think that they'd affect the player inventory because they're using the indices for a different IItemHandler...it seems I might be wrong though...?

Expand  

Had to check.

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.

Posted
  On 5/28/2020 at 5:29 PM, diesieben07 said:

I'm unable to reproduce the effect you showed in your video.

I clicked the slot with an item like a madman, the item does not go in.

 

I also smashed ^ and e in succession like a mad man to quickly switch between the inventory and your GUI. No duplication could be observed.

Expand  

That's super weird, I guess the only option now is to...reinstantiate (is that the correct term or even a word?!?!) the forge project and will see what happens

  On 5/28/2020 at 6:02 PM, Draco18s said:

Had to check.

Expand  

Was there anything that might've royally screwed me over in terms of adding the inventory?

Posted
  On 5/28/2020 at 6:41 PM, Nozzomi said:

Was there anything that might've royally screwed me over in terms of adding the inventory?

Expand  

If you had inadvertently linked the player inventory instead of your container inventory.

When that happens, you get a very similar effect to your video.

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.

Posted

Is it possible for me to extend on the player's regular ItemStackHandler capability? Maybe if I add the container through an already existing capability, it'll go more smoothly. How would I extend upon that capability?

Posted
  On 5/28/2020 at 7:12 PM, diesieben07 said:

Since I can't reproduce this on my end, you need to debug this yourself.

Put a breakpoing in insertItem (and setStackInSlot) of your item handler. Then reproduce the "wrong item in slot" bug and see where the method is called from.

Then report your findings here.

Expand  

I think what I've found is that inserItem and setStackInSlot isn't called when I try to ghost insert my item in the custom inventory, but the item somehow still ends up in the slot it's not supposed to be in. I also tried sticking an extra isItemValid() check in the setStackInSlot method before the super, but it ended up not showing the items, but if I clicked on the slot, the item would still be there, just no longer showing.

Posted
  On 5/28/2020 at 8:27 PM, diesieben07 said:

That's... not possible...

Expand  

Video

 

The sword is placed in according to the server but the breakpoint doesn't stop me when I click with the sword. The setStackInSlot part is because the item is already recognized as in there...? (It's definitely your word over mine, I'm a little lost)

Posted
  On 5/29/2020 at 5:25 PM, diesieben07 said:

Did some more digging. You never attach CapabilityCoreStorage.CORE_STORAGE_CAPABILITY to the player. Which is why getCapability for it always returns an empty optional. Which you ignore and just create an empty one. This is not how you handle errors. If you expect the capability to be there, throw an error if it's absent! This is how you get hard to debug problems like this. "Oh, something strange happend that I didn't expect? Oh well, carry on."

This is not PHP.

Expand  

Wait, but don't I? I have

e.addCapability(CapabilityCoreStorage.LOCATION, new CapabilityCoreStorage());

where LOCATION is just the ResourceLocation needed to attach the capability, right?

Posted (edited)

Also, I changed the orElse into an orElseThrow and it hasn't given me any errors (though I'm  not sure whether or not to be happy since the problem isn't any clearer...)

public static final RegistryObject<ContainerType<CoreStorageContainer>> CORE_STORAGE_CONTAINER = CONTAINERS.register("core_storage_container",
    () -> new ContainerType<>((id, inv) -> new CoreStorageContainer(id, inv, inv.player.getCapability(CapabilityCoreStorage.CORE_STORAGE_CAPABILITY).orElseThrow(() -> new NullPointerException("Core Storage Capability not found!")))));

 

Edited by Nozzomi
Posted
  On 5/30/2020 at 11:13 AM, diesieben07 said:

Please clone your own repo in a separate folder and check if you have the error there as well.

Expand  

Huh, I couldn't reproduce it either...

 

I ended up fixing the problem in the original code by creating a new world since I figured that if it worked in the git clone, it must've had something to do with the run folder. In hindsight, I probably should've created a new world in the first place since I was attaching a capability to the player. Thank you for helping me through!

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.