Jump to content

[1.11] OpenGui not working on Tile Entity


jtmnf
 Share

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

I got that same error when I tried to craft and axe from my tutorial mod (the axe has two recipes). My other recipes work fine. Just not the Tutorial Axe.

YouTube:

https://www.youtube.com/channel/UCaK5oRw4yd7PurBWww9tVhA

Kuribo64 (where I am most active):

http://kuribo64.net/board/profile.php?id=1423

 

Thanks for your answer!

 

Current projects:

 

3D Geometry Dash: 13%

Terracraft (MC Mod): 8%

New Super Kaizo Bros DS: 100% (no download for now :'( )

New Super Kaizo Bros. Wii: 12%

Super Mario Galaxy 1.5: 96%

New Super Mario Bros Galaxy: 85%

Kerbal Space Program Advance: 47%

MC CREATE: 20%

Mystery Projects: 10%, 40%, 13%, and 94%

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello I'm working on playing mods with friends but forge is giving me the exit code 1. I have tried using the curseforge to run it but same outcome. I've uninstalled minecraft and java. I looked online for any solutions and I've tried different versions of 1.19.2, nothing made a difference. There are currently no mods just forge. Log: https://gist.github.com/ExpiredPoptarts/19d7ff941fc62c9dc0b3b87ef3f65dc8
    • Custom lamp problem 1.12.2 is a problem that can occur when using the custom lamps mod in version 1.12.2 of Minecraft. The issue is caused when two or more custom lamps are placed in close proximity to each other, causing them to conflict with each other and malfunction. This can result in a variety of issues such as the lamps not lighting up, flickering, or not responding to game commands. The problem can be resolved by ensuring that custom lamps are placed far enough away from each other that they do not conflict.
    • look inside the model json file. move all cubes upward.
    • I made a huge forge 1.7.10 mod pack but whenever I try to create a singleplayer world I get the error saying "A fatal error has occurred, this connection is terminated." Does anyone know what the issue could be?  Here is my fml-client-latest.log from when it crashes: https://paste.ubuntu.com/p/3rKSJSqnrX/ and here is the list of mods: https://imgur.com/a/AZifMbg    
    • Im trying to host a minecraft server using the curseforge serverpack from FTB Direwolf20 and when I try to start the server I run into an error The Error: Starting server A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)         at java.lang.reflect.Method.invoke(Unknown Source)         at cpw.mods.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:43)         at cpw.mods.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:12) Caused by: java.lang.NoClassDefFoundError: org/apache/logging/log4j/Level         at net.minecraft.launchwrapper.Launch.launch(Launch.java:94)         at net.minecraft.launchwrapper.Launch.main(Launch.java:28)         ... 6 more Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.Level         at java.net.URLClassLoader$1.run(Unknown Source)         at java.net.URLClassLoader$1.run(Unknown Source)         at java.security.AccessController.doPrivileged(Native Method)         at java.net.URLClassLoader.findClass(Unknown Source)         at java.lang.ClassLoader.loadClass(Unknown Source)         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)         at java.lang.ClassLoader.loadClass(Unknown Source)         ... 8 more   I'have tried deleting and downloading the newset version of java wich didnt work and now im using an older version which is the 1.7.0_80 Here is what my Server folder looks like: https://ibb.co/jkbfRY7 Here is what the ServerStart.bat file looks like: @if NOT "%FTB_VERBOSE%"=="yes" ( @echo off ) call settings.bat if NOT EXIST minecraft_server.1.7.10.jar ( goto install ) if NOT EXIST libraries\%LAUNCHWRAPPER% ( goto install ) goto skipinstall :install echo running install script! call FTBInstall.bat :skipinstall REM Check if java in path REM TODO: use %JAVACMD% where java > NUL 2>&1 if %ERRORLEVEL% NEQ 0 ( echo No java binary in path. Can't run server, exiting... pause exit /B ) REM Test JVM REM e.g. 32-bit JVM does not have server\jvm.dll library java -server -version > java-test.log 2>&1 if %ERRORLEVEL% NEQ 0 ( echo Detected following JVM error: echo ======================================= more java-test.log echo ======================================= echo JVM test failed. Can't run server, Exiting... pause exit /B ) if not exist eula.txt ( echo Missing eula.txt. Startup will fail and eula.txt will be created echo Make sure to read eula.txt before playing! goto startserver ) find "eula=false" eula.txt 1 > NUL 2>&1 if %ERRORLEVEL% EQU 0 ( echo Make sure to read eula.txt before playing! Exiting. pause exit /B ) del /f /q autostart.stamp > nul 2>1 :startserver echo Starting server java -server -Xms512M -Xmx2048M -XX:PermSize=256M -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar FTBServer-1.7.10-1558.jar nogui :server_loop if exist autostart.stamp ( del /f /q autostart.stamp > nul 2>1 echo If you want to completely stop the server process now, press Ctrl+C before the time is up! for /l %%i in (5,-1,1) do ( echo Restarting server in %%i choice /t 1 /d y > nul ) echo Starting server now java -server -Xms512M -Xmx2048M -XX:PermSize=256M -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar FTBServer-1.7.10-1558.jar nogui echo Server process finished goto :server_loop ) echo Exiting... pause  
  • Topics

×
×
  • Create New...

Important Information

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