#Is there a way to make a block container?

1 messages · Page 1 of 1 (latest)

opaque cove
#

In minecraft modding it's possible to create a block container, for example to store items in it like a chest is it also possible with pnx?

carmine sentinel
#

Yes, you can create custom inventories for your blocks using a class inheriting ContainerInventory and using a BlockEntity holding an inventory

#

You can build on top of this:

public class MyBlockEntity extends BlockEntitySpawnableContainer {
    @Override
    protected ContainerInventory requireContainerInventory() {
        return new MyInventory(this);
    }

    @Override
    public Inventory getInventory() {
        return this.inventory;
    }
}
public class MyInventory extends ContainerInventory {
    public MyInventory(MyBlockEntity blockEntity) {
        super(blockEntity, InventoryType.INVENTORY, 27); // can also be dropper, hopper, ... - 27 for slots
    }

    public MyBlockEntity getHolder() {
        return (MyBlockEntity) super.getHolder();
    }
}

Missing here is the block itself and the inventory opening logic + stuff you may want to customize