Проблема с открытием GUI

Версия Minecraft
1.12.2
47
1
Привет всем) Проблема: есть блок с тайлом и у него должно быть гуи. Но при клике пкм по блоку оно не открывается. Игра не крашится, но в консоль пишет это.

error.jpg

Код:
@Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (!worldIn.isRemote)
        {
            TileEntitySpoilMachine tileEntity = (TileEntitySpoilMachine) worldIn.getTileEntity(pos);
            if (tileEntity instanceof TileEntitySpoilMachine)
            {
                player.displayGUIChest((TileEntitySpoilMachine)tileEntity);
            }
        }
        return true;
    }

Сам тайл наследуется от TileEntityLockable и встраивает интерфейсы ITickable, ISidedInventory

Код:
@Override
    public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
        return new ContainerSpoilMachine(playerInventory, this);
    }

ContainerSpoilMachine делал на примере контейнера печки.

Код:
public class GuiSpoilMachine extends GuiContainer
{
    
    private static final ResourceLocation TEXTURES = new ResourceLocation(ExperimentalProject.MODID + "gui/gui.png");

    private final InventoryPlayer player;
    private final TileEntitySpoilMachine tileentity;
    
    public GuiSpoilMachine(InventoryPlayer player, TileEntitySpoilMachine tileentity)
     {
        super(new ContainerSpoilMachine(player, tileentity));
        this.player = player;
        this.tileentity = tileentity;               
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
    {
             GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
            this.mc.getTextureManager().bindTexture(TEXTURES);
            this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
    }       
}

Код:
public class GuiHandler implements IGuiHandler
{
    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
    {
        ContainerSpoilMachine gui = new ContainerSpoilMachine(player.inventory, (TileEntitySpoilMachine)world.getTileEntity(new BlockPos(x,y,z)));
        return gui;
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
    {
        GuiSpoilMachine gui = new GuiSpoilMachine(player.inventory, (TileEntitySpoilMachine) world.getTileEntity(new BlockPos(x,y,z)));
        return gui;
    }   
}

В СommonProxy в init такая строчка
NetworkRegistry.INSTANCE.registerGuiHandler(ExperimentalProject.instance, new GuiHandler());

Если кто может подсказать, что делаю не так, то буду очень благодарен)) Спасибо!
 
Решение
Ну вообще-то нужно открывать гуи так: player.openGui(MyMod.instance, 0, world, posX, posY, posZ);// там где ноль - это id в GuiHandler.

Код:
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        player.openGui(ExperimentalProject.instance, 0, world, pos.getX(), pos.getY(), pos.getZ());
        return true;
    }
    return false;
}
Код:
public class GuiHandler implements IGuiHandler {
    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        final TileEntity tile = world.getTileEntity(new BlockPos(x, y, z))...

Icosider

Kotliner
Администратор
3,603
99
664
Ну вообще-то нужно открывать гуи так: player.openGui(MyMod.instance, 0, world, posX, posY, posZ);// там где ноль - это id в GuiHandler.

Код:
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        player.openGui(ExperimentalProject.instance, 0, world, pos.getX(), pos.getY(), pos.getZ());
        return true;
    }
    return false;
}
Код:
public class GuiHandler implements IGuiHandler {
    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        final TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
     
        if (tile instanceof TileEntitySpoilMachine) {
            return new ContainerSpoilMachine(player.inventory, tile);
        }
        return null;
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        final TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
     
        if (tile instanceof TileEntitySpoilMachine) {
            return new GuiSpoilMachine(player.inventory, tile);
        }
        return null;
    }
}
 
Последнее редактирование:
Сверху