Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

 

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).

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 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.