Posted July 16, 201411 yr I've been working on a wire block and I've been trying to make it render in certain places to make it join with other wires. I think I'm quite close, except the world is crashing when I try to load in on this line: return tileEntityCable.isWireAbove; Which is part of the rendering class. Inside the error log I get this error: java.lang.NullPointerException: Rendering Block Entity Any help on sorting this out would be useful, as I've spent quite a long time trying various things to no avail. Here is the rest of my code: Render class package foodTech.tileEntities.render; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.Entity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import foodTech.tileEntities.TileEntityCable; import foodTech.tileEntities.models.ModelCable; public class RenderCable extends TileEntitySpecialRenderer { ResourceLocation textureOff = (new ResourceLocation("roboguy99:textures/models/cableOff.png")); ResourceLocation textureOn = (new ResourceLocation("roboguy99:textures/models/cableOn.png")); public ModelCable modelCable; public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float scale) { boolean[] neighbourBlockWires = new boolean[6]; GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y - 0.5F, (float) z + 0.5F); Minecraft.getMinecraft().renderEngine.bindTexture(textureOff); neighbourBlockWires[0] = TileEntityCable.getWireAboveConnected(); neighbourBlockWires[1] = TileEntityCable.getWireBelowConnected(); neighbourBlockWires[2] = TileEntityCable.getWireNorthConnected(); neighbourBlockWires[3] = TileEntityCable.getWireSouthConnected(); neighbourBlockWires[4] = TileEntityCable.getWireEastConnected(); neighbourBlockWires[5] = TileEntityCable.getWireWestConnected(); this.modelCable = new ModelCable(neighbourBlockWires); this.modelCable.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glTranslatef((float) x - 0.5F, (float) y + 0.5F, (float) z - 0.5F); GL11.glPopMatrix(); } } TileEntity class package foodTech.tileEntities; import foodTech.blocks.CreateBlocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class TileEntityCable extends TileEntity { private boolean isWireAbove = false; private boolean isWireBelow = false; private boolean isWireNorth = false; private boolean isWireSouth = false; private boolean isWireEast = false; private boolean isWireWest = false; private static TileEntityCable tileEntityCable; private boolean[] allConnectionStates = new boolean[6]; public static void getAllConnectedWires(int x, int y, int z, World world) { if (world.getBlock(x, y+1, z).equals(CreateBlocks.blockCable)) tileEntityCable.isWireAbove = true; if (world.getBlock(x, y-1, z).equals(CreateBlocks.blockCable)) tileEntityCable.isWireBelow = true; if (world.getBlock(x+1, y, z).equals(CreateBlocks.blockCable)) tileEntityCable.isWireNorth = true; if (world.getBlock(x-1, y, z).equals(CreateBlocks.blockCable)) tileEntityCable.isWireSouth = true; if (world.getBlock(x, y, z+1).equals(CreateBlocks.blockCable)) tileEntityCable.isWireEast = true; if (world.getBlock(x, y, z-1).equals(CreateBlocks.blockCable)) tileEntityCable.isWireWest = true; tileEntityCable.allConnectionStates[0] = tileEntityCable.isWireAbove; tileEntityCable.allConnectionStates[1] = tileEntityCable.isWireBelow; tileEntityCable.allConnectionStates[2] = tileEntityCable.isWireNorth; tileEntityCable.allConnectionStates[3] = tileEntityCable.isWireSouth; tileEntityCable.allConnectionStates[4] = tileEntityCable.isWireEast; tileEntityCable.allConnectionStates[5] = tileEntityCable.isWireWest; } public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); tileEntityCable.isWireAbove = nbt.getBoolean("isWireAbove"); tileEntityCable.isWireBelow = nbt.getBoolean("isWireBelow"); tileEntityCable.isWireNorth = nbt.getBoolean("isWireNorth"); tileEntityCable.isWireSouth = nbt.getBoolean("isWireSouth"); tileEntityCable.isWireEast = nbt.getBoolean("isWireEast"); tileEntityCable.isWireWest = nbt.getBoolean("isWireWest"); } public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setBoolean("isWireAbove", isWireAbove); nbt.setBoolean("isWireBelow", isWireBelow); nbt.setBoolean("isWireNorth", isWireNorth); nbt.setBoolean("isWireSouth", isWireSouth); nbt.setBoolean("isWireEast", isWireEast); nbt.setBoolean("isWireWest", isWireWest); } public static boolean getWireAboveConnected() { return tileEntityCable.isWireAbove; } public static boolean getWireBelowConnected() { return tileEntityCable.isWireBelow; } public static boolean getWireNorthConnected() { return tileEntityCable.isWireNorth; } public static boolean getWireSouthConnected() { return tileEntityCable.isWireSouth; } public static boolean getWireEastConnected() { return tileEntityCable.isWireEast; } public static boolean getWireWestConnected() { return tileEntityCable.isWireWest; } } I have no idea what I'm doing.
July 16, 201411 yr Author Probably because I have no real idea what I'm doing and I'm making it up as I go along. If you could perhaps explain slightly more in depth about what I've got to do, I'll be thankful. EDIT: I've updated my code to what I've got now. EDIT 2: I've read what you put more carefully and updated my code to correspond with what you said. Do you think you could help me solve the problem now I have no idea what I'm doing.
July 17, 201411 yr Author Now you have a static field in your TileEntity, holding an instance of your TileEntity. But you never initialize it (apart from the fact that this doesn't make any sense at all). Also: all the methods in your TileEntity regarding the connection states are static. That is not right. Do you know what static means? It definitely sounds like you don't and you need to read up on that. Hmm ok. From my understanding of static, it means that other classes can access it. I also got told somewhere else that having static fields in a block class leads to the same result in all blocks of it's type, so after a quick bit of research I've found that the static modifier means the field/method is universal among all instances of that class. Do I just need to change the type of everything in the TileEntity class to not be static? Also I will do some research into what the static modifier does in more depth. EDIT: I've attempted to convert everything from the TileEntity class to non-static, but I'm stuck when it comes to neighbourBlockWires[0] = TileEntityCable.getWireAboveConnected(); neighbourBlockWires[1] = TileEntityCable.getWireBelowConnected(); neighbourBlockWires[2] = TileEntityCable.getWireNorthConnected(); neighbourBlockWires[3] = TileEntityCable.getWireSouthConnected(); neighbourBlockWires[4] = TileEntityCable.getWireEastConnected(); neighbourBlockWires[5] = TileEntityCable.getWireWestConnected(); How can I access the methods in a non-static way? I have no idea what I'm doing.
July 17, 201411 yr Author Ok thanks, but 1 more problem. The TileEntity passed in seems to just be a standard TileEntity class instance, and not one of TileEntityCable. Is this just me being stupid? I have no idea what I'm doing.
July 17, 201411 yr Author Thanks. Everything is almost working as I want it to. I've just got to change the directions around, but that bit's the easy bit. I have no idea what I'm doing.
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.