Posted July 14, 20205 yr I'm making a custom inventory (similar to curios or cosmetic armor) but I want to avoid using IInventory since its deprecated. What steps do i take to make one attached to a player that would open on a hit of a keybind?
July 15, 20205 yr Author I tried doing that, but im a bit confused on whether or not I need to make a readNBT and writeNBT for it. Do you need NBT data for an inventory not attached to an item? My code is here (Check the MCap fork) if you want to take a look. Right now it produces a nullpointerexception because of the readNBT function, and I can't figure out how to fix it. Edited July 15, 20205 yr by GarlicBread
July 16, 20205 yr Author Alright I fixed that issue, now I've basically made a trash can since the items I put in the slot disappear. Is there anything else I need to add to my code, or am I doing something wrong with the capabilities?
July 16, 20205 yr Author Hmm.. I added code in my ICapabilityProvider, and I think I'm not very sure what data I'm supposed to store. I took some code from ItemFlowerBag in MBE and I'm assuming this would work, but I still have the same issue. I have a feeling it's from this: but im not exactly sure how to fix this. I've looked at MBE examples and I think I'm following them correctly, but the capability is never equal to the capability that I've made. How do I get about to fixing it? @Override public INBT serializeNBT() { return CapabilityRestraintsInventory.INVENTORY.writeNBT(getCachedInventory(), null); } @Override public void deserializeNBT(INBT nbt) { CapabilityRestraintsInventory.INVENTORY.readNBT(getCachedInventory(), null, nbt); }
July 16, 20205 yr 15 minutes ago, GarlicBread said: Hmm.. I added code in my ICapabilityProvider, and I think I'm not very sure what data I'm supposed to store. I took some code from ItemFlowerBag in MBE and I'm assuming this would work, but I still have the same issue. I have a feeling it's from this: but im not exactly sure how to fix this. I've looked at MBE examples and I think I'm following them correctly, but the capability is never equal to the capability that I've made. How do I get about to fixing it? @Override public INBT serializeNBT() { return CapabilityRestraintsInventory.INVENTORY.writeNBT(getCachedInventory(), null); } @Override public void deserializeNBT(INBT nbt) { CapabilityRestraintsInventory.INVENTORY.readNBT(getCachedInventory(), null, nbt); } Okay, a few things. Provider#getCapability should return this, capability == CAPABILITY ? lazyOptional.cast() : LazyOptional.empty() You should use LazyOptional#cast instead of a real cast. Btw, the reason it says that's always false is because it's currently null, it only gets a value at runtime through magic annotation bs. As for your serialize and deserialize NBT methods, you shouldn't write to the capability, you should write to its storage, something like this, @Override public INBT serializeNBT() { return CAPABILITY.getStorage().writeNBT(CAPABILITY, lazyOptional.orElseThrow(() -> new IllegalArgumentException("LazyOptional is empty!")), null); } @Override public void deserializeNBT(INBT nbt) { CAPABILITY.getStorage().readNBT(CAPABILITY, lazyOptional.orElseThrow(() -> new IllegalArgumentException("LazyOptional is empty!")), null, nbt); } Edit: ...I have no idea what happened to the second example's formatting... Edited July 16, 20205 yr by Novârch It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".
July 16, 20205 yr Author Alright, I followed what you said and changed my code to the following: @Override public INBT serializeNBT() { return CapabilityRestraintsInventory.INVENTORY.getStorage().writeNBT(CapabilityRestraintsInventory.INVENTORY, lazyInitialisionSupplier.orElseThrow(() -> new IllegalArgumentException("LazyOptional is empty!")), null); } @Override public void deserializeNBT(INBT nbt) { CapabilityRestraintsInventory.INVENTORY.getStorage().readNBT(CapabilityRestraintsInventory.INVENTORY, lazyInitialisionSupplier.orElseThrow(() -> new IllegalArgumentException("LazyOptional is empty!")), null, nbt); } It still seems to act like a trash can, and it says it will produce an NPE on running .getStorage() on my capability, but I dont seem to get an NPE when going into the game. Does that have anything to do with the cap variable never being equal to my capability?
July 16, 20205 yr 18 minutes ago, GarlicBread said: cap variable never being equal to my capability As I said, the cap variable isn't equal to your capability because your capability is null in your IDE, it gets a value at runtime through magic annotation bs (@CapabilityInject). It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".
July 16, 20205 yr Author 1 minute ago, Novârch said: As I said, the cap variable isn't equal to your capability because your capability is null in your IDE, it gets a value at runtime through magic annotation bs (@CapabilityInject). ah,alright then. I got a bit confused cuz in MBE the capabilities dont seem to be null. Thanks for letting me know!
July 17, 20205 yr Author Is there anything else that I'm missing, or is there something I'm doing wrong because my custom inventory still seems to act like a trash can
July 18, 20205 yr Author Alright, I fixed that problem, now the issue im having is I can't add more than one slot to my container without the game crashing. It says that the array only has 0 and 1 when it crashes. Is there any way to change this? Edit: Solved this, marking thread as solved Edited July 18, 20205 yr by GarlicBread
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.