Jump to content

Recommended Posts

Posted

I've created a wire block, custom rendered in Techne. What I want for happen is for parts of the wire to show/hide depending on whether or not another wire is connected. This is working in theory and worked when I manually inputted connectivity states. Now I'm actually trying to get the data the game crashes on loading the world due to an uninitialized boolean array containing the connectivity states. If anyone could help me with getting the data from the block class to the rendering class that would be great.

 

Block class

package foodTech.blocks;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import foodTech.tileEntities.TileEntityCable;

public class BlockCable extends BlockContainer
{
/**
 * Contains 6 values for each face of a cable block
 * up, down, north, south, east, west
 */

public BlockCable(Material material)
{
	super(material);
	float pixel = 1F/16F;
	this.setBlockBounds(12*pixel/2, 12*pixel/2, 12*pixel/2, 1-12*pixel/2, 1-12*pixel/2, 1-12*pixel/2);
	this.useNeighborBrightness = true;
}

public int getRenderType()
{
	return -1;
}

public boolean isOpaqueCube()
{
	return false;
}

public boolean renderAsNormalBlock()
{
	return false;
}

public TileEntity createNewTileEntity(World world, int var2) 
{
	return new TileEntityCable();
}


public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
{
    TileEntityCable.getConnectedWires(x, y, z, world);
}

public void updateTick(World world, int x, int y, int z, Random rand)
{
	TileEntityCable.getConnectedWires(x, y, z, world);
}

public void onBlockAdded(World world, int x, int y, int z)
{
	TileEntityCable.getConnectedWires(x, y, z, world);
}
}

 

Rendering 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;
private boolean[] neighbourBlockWires = {false, false, false, false, false, false};

public RenderCable()
{
	this.modelCable = new ModelCable(this.neighbourBlockWires);
}

public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float scale) 
{
	GL11.glPushMatrix();
		GL11.glTranslatef((float) x + 0.5F, (float) y - 0.5F, (float) z + 0.5F);

		Minecraft.getMinecraft().renderEngine.bindTexture(textureOff);

		this.neighbourBlockWires = TileEntityCable.getAllConectionStates();
		this.modelCable = new ModelCable(this.neighbourBlockWires); //Crashes here

		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 static boolean isWireAbove;
private static boolean isWireBelow;
private static boolean isWireNorth;
private static boolean isWireSouth;
private static boolean isWireEast;
private static boolean isWireWest;
private static boolean[] allConnectionStates;

public static void getConnectedWires(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[] getAllConectionStates()
 {
	 return TileEntityCable.allConnectionStates;
 }
}

 

If you need to see any more of my code I can upload it.

I have no idea what I'm doing.

Posted

You can't store a boolean array in the Block class. In fact, the only way you can store data specific to a block in the world is to set its metadata, or use a TileEntity (which you are).

 

As you have six directions of connections, and only 4 bits of metadata, the TileEntity is where you want to be storing the connections.

Posted

Ok I can sorta see what you're saying, but I'm slightly confused on how to migrate it. Could you point me in the right direction with that please?

I have no idea what I'm doing.

Posted

Wow, NBT? This is more complicated than I expected. Thanks for the help though. I'll go away and have a go, and report back here if I don't succeed. How do I check on block updates if I'm working in the tile entity though (or do I just call the method from the block update method in the block class)?

I have no idea what I'm doing.

Posted

Sure, move the field and related methods to the TileEntity, and look into reading from/writing to NBT :)

 

Ok I've had a go, re-written things a bit and tried to incorporate NBT, but I'm getting the exact same result. If you could help me a little more thoroughly at this point I'd be very grateful as I'm not really sure what I'm doing any more. I'm going to edit the code in the original post.

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.

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.