Posted August 4, 20178 yr Obligatory disclaimer... I have extremely little prior java experience. I've gone through several online guides and exercises, but by no means am I well versed in it, nor Eclipse (my IDE). Obviously this is also my first mod. I have been trying to implement a basic backpack (craft and use it). Nothing fancy, but this is a key stepping stone for my mod. Successes thus far - Getting my mod info to show in MC, getting the item to appear, getting the model to appear (it has, however, disappeared in the mean time), implementing a crafting recipe for the backpack. However... it doesn't do anything. I've scoured the internet, but I've only found examples for IInventory (Which should not be used anymore?) or half implementations. Stuck with the half implementations, a few 1.12 guides on making a chest... this is the basics of what I have. Is there any theoretical errors? Will post code, but I first want to know if my theory is wrong. Item class, produced by crafting recipe. This contains an IItemStackHandler, and a custom capability that implements ICapabilityProvider. The onRightClick action result override calls a gui to open. It also overrides initCapabilities to provide the custom capability. Custom capability contains an IItemHandler. Spoiler public IItemHandler myItemHandler; @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } else { return false; } } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(myItemHandler); } else { return null; } } I have a container, gui and gui proxy. The gui proxy gets called, but crashes when the container adds the slots for the item. Container's code: Spoiler private ItemStack pocketItemStack; public PocketContainer(IInventory playerInventory, ItemStack pocketItemStackIn) { this.pocketItemStack = pocketItemStackIn; addPlayerSlots(playerInventory); addOwnSlots(); } private void addOwnSlots() { IItemHandler itemHandler = this.pocketItemStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); int x = 9; int y = 6; // Add our own slots int slotIndex = 0; for (int i = 0; i < itemHandler.getSlots(); i++) { addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex, x, y)); slotIndex++; x += 18; } } Any ideas? Hints? Directions to a 1.12 tutorial on implementing backpacks...? (I've been through multiple githubs, but the amount of extra's (honestly) confuses me so much I can't identify what the basic implementation is).
August 5, 20178 yr i think that for this you dont make a custom capability but just use the arelady made IItemHandler also provide crah report to get help with it tutor for containers (shloud work for 1.12) Edited August 5, 20178 yr by lukas2005
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.