Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hoppers Can't Interact With Custom Block Entity Inventory #837

Open
xXStrayXx opened this issue May 21, 2024 · 2 comments
Open

Hoppers Can't Interact With Custom Block Entity Inventory #837

xXStrayXx opened this issue May 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@xXStrayXx
Copy link

Minecraft Version

1.20.1

KubeJS Version

2001.6.5-build.7

Rhino Version

2001.2.2-build.18

Architectury Version

9.2.14

Forge/Fabric Version

Forge 47.2.0

Describe your issue

When creating an custom block entity like this:
StartupEvents.registry("block", (event) => { event.create("test") .blockEntity((entityInfo) => { entityInfo.inventory(9, 3); entityInfo.rightClickOpensInventory(); }) })
It seems that the inventory of said block entity cannot be interacted by anything but player. Things like vanilla hoppers and create funnels completely ignore the inventory. This is probably because the inventory of the custom block entity isn't a regular inventory but rather a custom attactment.
I'm not certain whether this is intentional.

Crash report/logs

No response

@xXStrayXx xXStrayXx added the bug Something isn't working label May 21, 2024
@Classified3939
Copy link

Classified3939 commented Oct 1, 2024

For those who also encounter this problem on 1.20.1, PowerfulJS seems to be the solution. Here's some example code for a block that has no manual inventory, but gives an attached hopper 1 sugarcane per second:

StartupEvents.registry('block', event => {
event.create('basic_sugarcane_generator')
.blockEntity(blockInfo => {
blockInfo.inventory(9, 1);
blockInfo.serverTick(20, 0, entity => {
entity.inventory.insertItem('sugar_cane', false);
}),
blockInfo.attachCapability(
CapabilityBuilder.ITEM.blockEntity()
.extractItem((blockEntity, slot, amount, simulate) =>
blockEntity.inventory.extractItem(slot, amount, simulate)
)
.insertItem((blockEntity, slot, stack, simulate) =>
blockEntity.inventory.insertItem(slot, stack, simulate)
)
.getSlotLimit((blockEntity, slot) =>
blockEntity.inventory.getSlotLimit(slot)
)
.getSlots((blockEntity) => blockEntity.inventory.slots)
.getStackInSlot((blockEntity, slot) =>
blockEntity.inventory.getStackInSlot(slot)
)
);
})
[assorted block properties go here]
});

note that while you might not think the "insert Item" function is needed, removing it will make any item hoppered into the block, accidentally or otherwise, vanish into oblivion.

@EvanHsieh0415
Copy link
Contributor

Use PowerfulJS

https://discord.com/channels/303440391124942858/1251063549145645066

StartupEvents.registry("block", (event) => {
  event.create("kubejs:barrel").blockEntity((info) => {
    info.inventory(9, 3);
    info.rightClickOpensInventory();
    info.attachCapability(
      CapabilityBuilder.ITEM.blockEntity()
        .extractItem((blockEntity, slot, amount, simulate) => blockEntity.inventory.extractItem(slot, amount, simulate))
        .insertItem((blockEntity, slot, stack, simulate) => blockEntity.inventory.insertItem(slot, stack, simulate))
        .getSlotLimit((blockEntity, slot) => blockEntity.inventory.getSlotLimit(slot))
        .getSlots((blockEntity) => blockEntity.inventory.slots)
        .getStackInSlot((blockEntity, slot) => blockEntity.inventory.getStackInSlot(slot))
        .isItemValid((blockEntity, slot, stack) => blockEntity.inventory.isItemValid(slot, stack))
        .availableOn((blockEntity, direction) => direction != Direction.UP)
    );
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants