I tried the following:
@Override
public boolean onBlockActivated(BlockState state, World world, BlockPos pos,
PlayerEntity player, Hand hand, BlockRayTraceResult result) {
player.openContainer(state.getContainer(world, pos));
return true;
}
@Override
public INamedContainerProvider getContainer(BlockState state, World world, BlockPos pos) {
return new SimpleNamedContainerProvider((i, playerInventory, playerEntity)
-> new WorkbenchContainer(0, playerInventory), TEXT_COMPONENT);
}
This opens a crafting GUI, but does some mess in the inventory when opening - some items disappear, some get moved to other slot or duplicated, and everything returns back after leaving the GUI and clicking on any item in the inventory. What am I doing wrong?