Posted January 25, 201510 yr Hello everyone This is my first post here, so my apologies in advance if I do anything wrong! So, I've been following a few tutorials and things seem to go pretty smooth. The only problem that I have is when I set the blockbounds of a block inside the AxisAlignedBB function. In the crash log I get 'Unreported exception thrown'. Here is my full crash thingie that I get in the Eclipse console: [13:01:05] [Client thread/FATAL]: Unreported exception thrown! java.lang.NullPointerException at com.jstylezzz.allincluded.block.UICopperCable.getCollisionBoundingBoxFromPool(UICopperCable.java:40) ~[uICopperCable.class:?] at net.minecraft.world.World.canPlaceEntityOnSide(World.java:3647) ~[World.class:?] at net.minecraft.item.ItemBlock.func_150936_a(ItemBlock.java:172) ~[itemBlock.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:383) ~[PlayerControllerMP.class:?] at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1519) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2034) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1029) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?] at GradleStart.main(GradleStart.java:45) [start/:?] [13:01:05] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ---- // Hey, that tickles! Hehehe! Time: 1/25/15 1:01 PM Description: Unexpected error java.lang.NullPointerException: Unexpected error at com.jstylezzz.allincluded.block.UICopperCable.getCollisionBoundingBoxFromPool(UICopperCable.java:40) at net.minecraft.world.World.canPlaceEntityOnSide(World.java:3647) at net.minecraft.item.ItemBlock.func_150936_a(ItemBlock.java:172) at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:383) at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1519) at net.minecraft.client.Minecraft.runTick(Minecraft.java:2034) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1029) at net.minecraft.client.Minecraft.run(Minecraft.java:951) at net.minecraft.client.main.Main.main(Main.java:164) 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 net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) at GradleStart.main(GradleStart.java:45) It only happens when the following function is not commented out: this.setBlockBounds(11*pixel/2, 11*pixel/2, 11*pixel/2-(cable.connections[3] !=null?(11*pixel/2):0), 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2); The whole callback is as follows public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { TileEntityCable cable = (TileEntityCable) world.getTileEntity(x, y, z); float pixel = 1F/16; this.setBlockBounds(11*pixel/2, 11*pixel/2, 11*pixel/2-(cable.connections[3] !=null?(11*pixel/2):0), 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2); return AxisAlignedBB.getBoundingBox((double)x+minX, (double)y+minY,(double)z+minZ, (double)x+maxX, (double)y+maxY, (double)z+maxZ); } Note, that Minecraft only crashes if I place the block down. If a block is already placed down in the world, it does not make minecraft crash, but it also doesn't change the blockbounds. I'm sure that there is something that I'm doing wrong, but I really can't seem to find out what it is.. I hope someone here knows what's going on, all the help is much appreciated. Thanks in advance! EDIT: lol, I'm sorry for those posts (which I removed again), it seems I pressed the wrong button
January 25, 201510 yr cable.connections is null. 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/
January 25, 201510 yr Author But the ':0' thing at the end should set that thingie to '0' if it is null right? (cable.connections[3] !=null?(11*pixel/2):0)
January 25, 201510 yr No, the connections array is null, so when trying to access connections[3] , it will throw a NPE. 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/
January 25, 201510 yr Author Ah I see, thanks for the heads up I'm not really sure what I should change though, the 'connections' is basically this public ForgeDirection [] connections = new ForgeDirection[6]; //and then public void updateConnections() //Called on updateEntity { if(worldObj.getTileEntity(xCoord, yCoord+1, zCoord) instanceof TileEntityCable) connections[0] = ForgeDirection.UP; else connections[0] = null; if(worldObj.getTileEntity(xCoord, yCoord-1, zCoord) instanceof TileEntityCable) connections[1] = ForgeDirection.DOWN; else connections[1] = null; if(worldObj.getTileEntity(xCoord, yCoord, zCoord-1) instanceof TileEntityCable) connections[2] = ForgeDirection.NORTH; else connections[2] = null; if(worldObj.getTileEntity(xCoord+1, yCoord, zCoord) instanceof TileEntityCable) connections[3] = ForgeDirection.EAST; else connections[3] = null; if(worldObj.getTileEntity(xCoord, yCoord, zCoord+1) instanceof TileEntityCable) connections[4] = ForgeDirection.SOUTH; else connections[4] = null; if(worldObj.getTileEntity(xCoord-1, yCoord, zCoord) instanceof TileEntityCable) connections[5] = ForgeDirection.WEST; else connections[5] = null; } Is there a way to get around that NPE? Thanks for the answers so far
January 25, 201510 yr Then the only other thing that can be null on that line is cable . Can you post your full block class? 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/
January 25, 201510 yr Author Sure I can package com.jstylezzz.allincluded.block; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import com.jstylezzz.allincluded.AllIncluded; import com.jstylezzz.allincluded.entity.TileEntityCable; public class UICopperCable extends BlockContainer { public UICopperCable() { super(Material.cloth); setStepSound(Block.soundTypeStone); setCreativeTab(CreativeTabs.tabBlock); setCreativeTab(AllIncluded.allIncluded); setBlockName("uiCopperCable"); setBlockTextureName("allincluded:uiCopperCable"); setHardness(1.0f); useNeighborBrightness=true; float pixel = 1F/16; setBlockBounds(11*pixel/2, 11*pixel/2, 11*pixel/2, 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2); } public TileEntity createNewTileEntity(World world, int i) { return new TileEntityCable(); } public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { TileEntityCable cable = (TileEntityCable) world.getTileEntity(x, y, z); float pixel = 1F/16; float f = 0; if(cable.connections[3] == null) f = 0; else f = 11*pixel/2; this.setBlockBounds(11*pixel/2, 11*pixel/2, 11*pixel/2-(f), 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2); return AxisAlignedBB.getBoundingBox((double)x+minX, (double)y+minY,(double)z+minZ, (double)x+maxX, (double)y+maxY, (double)z+maxZ); } public int getRenderType(){ return -1; } public boolean isOpaqueCube(){ return false; } public boolean renderAsNormalBlock() { return false; } } Here is the UICopperCable class. if connections[x] != null do it with the connection else do something else ? I tried something like this, but it still doesn't like it very much. Thanks anyways!
January 25, 201510 yr You need to have the public boolean hasTileEntity(int meta) in your block class and make it return true. 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/
January 25, 201510 yr Author I added public boolean hasTileEntity(int meta) { return true; } into the UICopperCable class file. It still crashes when I place down the block though. Is there anything else a tileEntity block should have in it's class that I missed?
January 25, 201510 yr Ah, now I see the issue. You have called your method createNewTileEntity while it should be createTileEntity . In the future, add the @Override annotation to all your methods you expect to override a method, as it will throw an error if the method doesn't exist in one of the super classes. 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/
January 25, 201510 yr Author Ah, thanks a lot for looking I think we nearly solved this problem, yey I added the override @Override public TileEntity createNewTileEntity(World world, int i) { return new TileEntityCable(); } When I change createNewTileEntity to createTileEntity it gives me an error, so I tried it like I paste above. It still crashes on me though Thanks for helping me, and sorry for being so difficult!
January 25, 201510 yr So this is giving you an error? @Override public TileEntity createTileEntity(World world, int meta) { return new TileEntityCable(); } It should work if it's like that. You still have the hasTileEntity method? 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/
January 25, 201510 yr Author Yeah, I still have it. This is what Eclipse says: 'The type UICopperCable must implement the inherited abstract method ITileEntityProvider.createNewTileEntity(World, int)'. It has the option to add the unimplemented method, but that just adds the createNewTileEntity thing that we just changed..
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.