:clue:
So… I looked into what minecraft did for blocks, and it was cool sounding to me. In Block.class, he defined a whole bunch of blocks, their traits, and used a seperate class for all the block-specific methods needed. Like this:
EXERPT FROM Minecraft’s Block.java
public static final Block stone = (new BlockStone(1)).setHardness(1.5F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("stone").setTextureName("stone");
public static final BlockGrass grass = (BlockGrass)(new BlockGrass(2)).setHardness(0.6F).setStepSound(soundGrassFootstep).setUnlocalizedName("grass").setTextureName("grass");
public static final Block dirt = (new BlockDirt(3)).setHardness(0.5F).setStepSound(soundGravelFootstep).setUnlocalizedName("dirt").setTextureName("dirt");
public static final Block cobblestone = (new Block(4, Material.rock)).setHardness(2.0F).setResistance(10.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("stonebrick").setCreativeTab(CreativeTabs.tabBlock).setTextureName("cobblestone");
public static final Block planks = (new BlockWood(5)).setHardness(2.0F).setResistance(5.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("wood").setTextureName("planks");
public static final Block sapling = (new BlockSapling(6)).setHardness(0.0F).setStepSound(soundGrassFootstep).setUnlocalizedName("sapling").setTextureName("sapling");
public static final Block bedrock = (new Block(7, Material.rock)).setBlockUnbreakable().setResistance(6000000.0F).setStepSound(soundStoneFootstep).setUnlocalizedName("bedrock").disableStats().setCreativeTab(CreativeTabs.tabBlock).setTextureName("bedrock");
public static final BlockFluid waterMoving = (BlockFluid)(new BlockFlowing(8, Material.water)).setHardness(100.0F).setLightOpacity(3).setUnlocalizedName("water").disableStats().setTextureName("water_flow");
So every time you wanted to reference a block, you would do (I assume, since all the obfuscation for making the blocks is too hard to decipher):
blocksinworld[0][1][1000] = Block.planks;
So I did that with my blocks:
Voxel[][] returning = new Voxel[2][2];
returning[0][0] = (Voxel) Voxel.dirt.setPos(4, 0, 4);
returning[0][1] = (Voxel) Voxel.dirt.setPos(4, 0, 5);
returning[1][0] = (Voxel) Voxel.dirt.setPos(5, 0, 4);
returning[1][1] = (Voxel) Voxel.dirt.setPos(5, 0, 5);
return returning;
And my Voxel.java:
public class Voxel extends Entity {
Texture texture;
public static final Voxel dirt = new VoxelDirt();
public Voxel(String name) {
super(name);
try {
texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/default_vox.png"), GL_NEAREST);
} catch (Exception e) {
e.printStackTrace();
}
}
public void update() {
}
public void render() {
glPushMatrix();
glTranslatef(x, y, z);
//renders all the vertices using vertex array objects. Don't judge.
TVAO(24, 3, 2, new float[]{
1,0,0, 1,1,0, 1,1,1, 1,0,1,
0,1,0, 1,1,0, 1,1,1, 0,1,1,
0,0,1, 1,0,1, 1,1,1, 0,1,1,
0,1,1, 0,0,1, 0,0,0, 0,1,0,
1,0,1, 0,0,1, 0,0,0, 1,0,0,
1,1,0, 0,1,0, 0,0,0, 1,0,0,
}, new float[] {
0,0, 1,0, 1,1, 0,1,
0,0, 1,0, 1,1, 0,1,
0,0, 1,0, 1,1, 0,1,
0,0, 1,0, 1,1, 0,1,
0,0, 1,0, 1,1, 0,1,
0,0, 1,0, 1,1, 0,1,
}, texture);
glPopMatrix();
}
}
But that just produces this: