Jump to content

[1.11] OpenGui not working on Tile Entity


jtmnf

Recommended Posts

Hi guys! So, if I have this piece of code on the Container, it crashes the game (but it doesn't close it).

 

for (int y = 0; y < 3; ++y) {
    for (int x = 0; x < 3; ++x) {
        this.addSlotToContainer(new Slot(this.crusherTileEntity, x + y * 3, 62 + x * 18, 17 + y * 18));
    }
}

 

If the addSlotToContainer is commented, the GUI opens normally and it doesn't crash the game. I already saw the implementation of the chest, by the way.

 

The error is:

 

 

 

java.util.concurrent.ExecutionException: java.lang.NullPointerException: The validated object is null

at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_92]

at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_92]

at net.minecraft.util.Util.runTask(Util.java:27) [util.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?]

at java.lang.Thread.run(Thread.java:745) [?:1.8.0_92]

Caused by: java.lang.NullPointerException: The validated object is null

at org.apache.commons.lang3.Validate.notNull(Validate.java:222) ~[commons-lang3-3.3.2.jar:3.3.2]

at org.apache.commons.lang3.Validate.notNull(Validate.java:203) ~[commons-lang3-3.3.2.jar:3.3.2]

at net.minecraft.util.NonNullList.add(NonNullList.java:54) ~[NonNullList.class:?]

at java.util.AbstractList.add(AbstractList.java:108) ~[?:1.8.0_92]

at net.minecraft.inventory.Container.getInventory(Container.java:64) ~[Container.class:?]

at net.minecraft.inventory.Container.addListener(Container.java:53) ~[Container.class:?]

at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:100) ~[FMLNetworkHandler.class:?]

at jtmnf.blocks.machines.Crusher.onBlockActivated(Crusher.java:54) ~[Crusher.class:?]

at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:474) ~[PlayerInteractionManager.class:?]

at net.minecraft.network.NetHandlerPlayServer.processRightClickBlock(NetHandlerPlayServer.java:701) ~[NetHandlerPlayServer.class:?]

at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]

at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]

at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_92]

at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_92]

at net.minecraft.util.Util.runTask(Util.java:26) ~[util.class:?]

... 5 more

[02:07:41] [server thread/ERROR]: Encountered an unexpected exception

net.minecraft.util.ReportedException: Ticking player

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:800) ~[MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) ~[MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?]

at java.lang.Thread.run(Thread.java:745) [?:1.8.0_92]

Caused by: java.lang.NullPointerException

at net.minecraft.item.ItemStack.areItemStacksEqual(ItemStack.java:442) ~[itemStack.class:?]

at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:89) ~[Container.class:?]

at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:292) ~[EntityPlayerMP.class:?]

at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2134) ~[World.class:?]

at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:875) ~[WorldServer.class:?]

at net.minecraft.world.World.updateEntity(World.java:2101) ~[World.class:?]

at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:676) ~[WorldServer.class:?]

at net.minecraft.world.World.updateEntities(World.java:1890) ~[World.class:?]

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:647) ~[WorldServer.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:794) ~[MinecraftServer.class:?]

... 4 more

 

 

Thanks :)

João Fernandes

Link to comment
Share on other sites

My guess:

Your TE has an inventory that contains null items.  in 1.11 you can't have null ItemStacks, you have to use stacks of air.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I didn't knew that, thanks!

 

After fixing that, now it just crashes with a rendering problem...

 

 

 

net.minecraft.util.ReportedException: Rendering screen

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1191) ~[EntityRenderer.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1138) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:405) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_92]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_92]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_92]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_92]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_92]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_92]

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]

at GradleStart.main(GradleStart.java:26) [start/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_92]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_92]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_92]

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:?]

Caused by: java.lang.NullPointerException

at net.minecraft.client.gui.inventory.GuiContainer.drawSlot(GuiContainer.java:274) ~[GuiContainer.class:?]

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:117) ~[GuiContainer.class:?]

at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:382) ~[ForgeHooksClient.class:?]

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1164) ~[EntityRenderer.class:?]

... 20 more

 

 

Thanks :)

João Fernandes

Link to comment
Share on other sites

Here it is:

 

TileEntity

public class CrusherTileEntity extends TileEntity implements IInventory {

    private ItemStack[] inventory;
    private String customName;

    public CrusherTileEntity() {
        this.inventory = new ItemStack[this.getSizeInventory()];

        for (int i = 0; i < inventory.length; i++) {
            inventory[i] = new ItemStack(Blocks.AIR);
        }
    }

    public String getCustomName() {
        return this.customName;
    }

    public void setCustomName(String customName) {
        this.customName = customName;
    }

    @Override
    public String getName() {
        return this.hasCustomName() ? this.customName : "container:crusher_tile_entity";
    }

    @Override
    public boolean hasCustomName() {
        return this.customName != null && !this.customName.equals("");
    }

    @Nullable
    @Override
    public ITextComponent getDisplayName() {
        return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName());
    }

    @Override
    public int getSizeInventory() {
        return 27;
    }

    @Override
    public ItemStack getStackInSlot(int index) {
        if (index < 0 || index >= this.getSizeInventory()) {
            return null;
        }

        return this.inventory[index];
    }

    @Override
    public ItemStack decrStackSize(int index, int count) {
        if (this.getStackInSlot(index) != null) {
            ItemStack itemstack;

            if (this.getStackInSlot(index).func_190916_E() <= count) {
                itemstack = this.getStackInSlot(index);
                this.setInventorySlotContents(index, null);
                this.markDirty();
                return itemstack;
            } else {
                itemstack = this.getStackInSlot(index).splitStack(count);

                if (this.getStackInSlot(index).func_190916_E() <= 0) {
                    this.setInventorySlotContents(index, null);
                } else {
                    //Just to show that changes happened
                    this.setInventorySlotContents(index, this.getStackInSlot(index));
                }

                this.markDirty();
                return itemstack;
            }
        } else {
            return null;
        }
    }

    @Override
    public void setInventorySlotContents(int index, ItemStack stack) {
        if (index < 0 || index >= this.getSizeInventory())
            return;

        if (stack != null && stack.func_190916_E() > this.getInventoryStackLimit())
            stack.func_190920_e(this.getInventoryStackLimit());

        if (stack != null && stack.func_190916_E() == 0)
            stack = null;

        this.inventory[index] = stack;
        this.markDirty();
    }

    @Override
    public int getInventoryStackLimit() {
        return 64;
    }

    @Override
    public boolean isUseableByPlayer(EntityPlayer player) {
        return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64;
    }

    @Override
    public void openInventory(EntityPlayer player) {
    }

    @Override
    public void closeInventory(EntityPlayer player) {
    }

    @Override
    public boolean isItemValidForSlot(int index, ItemStack stack) {
        return true;
    }

    @Override
    public int getField(int id) {
        return 0;
    }

    @Override
    public void setField(int id, int value) {
    }

    @Override
    public int getFieldCount() {
        return 0;
    }

    @Override
    public void clear() {
        for (int i = 0; i < this.getSizeInventory(); i++)
            this.setInventorySlotContents(i, null);
    }


    @Override
    public boolean func_191420_l() {
        return false;
    }

    @Override
    public ItemStack removeStackFromSlot(int index) {
        return null;
    }
}

 

Container of the TileEntity

public class ContainerCrusher extends Container {

    private CrusherTileEntity crusherTileEntity;

    public ContainerCrusher(IInventory iInventory, CrusherTileEntity crusherTileEntity) {
        this.crusherTileEntity = crusherTileEntity;

        int numRows = crusherTileEntity.getSizeInventory() / 9;
        int i = (numRows - 4) * 18;

        for (int j = 0; j < numRows; ++j)
        {
            for (int k = 0; k < 9; ++k)
            {
                this.addSlotToContainer(new Slot(crusherTileEntity, k + j * 9, 8 + k * 18, 18 + j * 18));
            }
        }


        for (int y = 0; y < 3; ++y) {
            for (int x = 0; x < 9; ++x) {
                this.addSlotToContainer(new Slot(iInventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
            }
        }

        for (int x = 0; x < 9; ++x) {
            this.addSlotToContainer(new Slot(iInventory, x, 8 + x * 18, 142));
        }
    }

    @Override
    public boolean canInteractWith(EntityPlayer playerIn) {
        return crusherTileEntity.isUseableByPlayer(playerIn);
    }
}

 

Gui of the TileEntity

public class GuiCrusher extends GuiContainer {
    private IInventory playerInv;
    private CrusherTileEntity crusherTileEntity;

    public GuiCrusher(IInventory playerInv, CrusherTileEntity crusherTileEntity) {
        super(new ContainerCrusher(playerInv, crusherTileEntity));

        this.playerInv = playerInv;
        this.crusherTileEntity = crusherTileEntity;

        this.xSize = 176;
        this.ySize = 166;
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
        this.mc.getTextureManager().bindTexture(new ResourceLocation("pureadditions:textures/gui/container/crusher.png"));
        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
        String s = this.crusherTileEntity.getDisplayName().getUnformattedText();
        this.fontRendererObj.drawString(s, 88 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);            //#404040
        this.fontRendererObj.drawString(this.playerInv.getDisplayName().getUnformattedText(), 8, 72, 4210752);      //#404040
    }
}

 

Thanks :)

João Fernandes

Link to comment
Share on other sites

Don't use

IInventory

. Use

IItemHandler

in combination with Capabilities.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Use SlotItemHandler.  Duh.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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