Further adapt the multiblock code.

This will allow inter-block connected textures. I'll try and get side-specific texture overrides (eg. for the Salination Controller) working next.
This commit is contained in:
Ben Spiers 2014-09-01 18:19:21 +01:00
parent 5ae5036e62
commit b1a11b0ba2
13 changed files with 116 additions and 108 deletions

View file

@ -2,7 +2,9 @@ package mekanism.client.render;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
@ -81,55 +83,51 @@ public class CTM
{},
};
public static int[] getSubmapIndices(IBlockAccess world, int x, int y, int z, int side, List<Integer> metas)
public static int[] getSubmapIndices(IBlockAccess world, int x, int y, int z, int side, HashMap<Block, List<Integer>> blockMetas)
{
int index = getTexture(world, x, y, z, side, metas);
int index = getTexture(world, x, y, z, side, blockMetas);
return submaps[index];
}
public static int getTexture(IBlockAccess world, int x, int y, int z, int side, List<Integer> metas)
public static int getTexture(IBlockAccess world, int x, int y, int z, int side, HashMap<Block, List<Integer>> blockMetas)
{
if(world == null)
return 0;
int texture = 0;
Block block = world.getBlock(x, y, z);
if(metas == null || metas.size() <= 0)
metas = Arrays.asList(world.getBlockMetadata(x, y, z));
boolean b[] = new boolean[6];
if(side <= 1)
{
b[0] = isConnected(world, x - 1, y, z, side, block, metas);
b[1] = isConnected(world, x + 1, y, z, side, block, metas);
b[2] = isConnected(world, x, y, z + 1, side, block, metas);
b[3] = isConnected(world, x, y, z - 1, side, block, metas);
b[0] = isConnected(world, x - 1, y, z, side, blockMetas);
b[1] = isConnected(world, x + 1, y, z, side, blockMetas);
b[2] = isConnected(world, x, y, z + 1, side, blockMetas);
b[3] = isConnected(world, x, y, z - 1, side, blockMetas);
} else if(side == 2)
{
b[0] = isConnected(world, x + 1, y, z, side, block, metas);
b[1] = isConnected(world, x - 1, y, z, side, block, metas);
b[2] = isConnected(world, x, y - 1, z, side, block, metas);
b[3] = isConnected(world, x, y + 1, z, side, block, metas);
b[0] = isConnected(world, x + 1, y, z, side, blockMetas);
b[1] = isConnected(world, x - 1, y, z, side, blockMetas);
b[2] = isConnected(world, x, y - 1, z, side, blockMetas);
b[3] = isConnected(world, x, y + 1, z, side, blockMetas);
} else if(side == 3)
{
b[0] = isConnected(world, x - 1, y, z, side, block, metas);
b[1] = isConnected(world, x + 1, y, z, side, block, metas);
b[2] = isConnected(world, x, y - 1, z, side, block, metas);
b[3] = isConnected(world, x, y + 1, z, side, block, metas);
b[0] = isConnected(world, x - 1, y, z, side, blockMetas);
b[1] = isConnected(world, x + 1, y, z, side, blockMetas);
b[2] = isConnected(world, x, y - 1, z, side, blockMetas);
b[3] = isConnected(world, x, y + 1, z, side, blockMetas);
} else if(side == 4)
{
b[0] = isConnected(world, x, y, z - 1, side, block, metas);
b[1] = isConnected(world, x, y, z + 1, side, block, metas);
b[2] = isConnected(world, x, y - 1, z, side, block, metas);
b[3] = isConnected(world, x, y + 1, z, side, block, metas);
b[0] = isConnected(world, x, y, z - 1, side, blockMetas);
b[1] = isConnected(world, x, y, z + 1, side, blockMetas);
b[2] = isConnected(world, x, y - 1, z, side, blockMetas);
b[3] = isConnected(world, x, y + 1, z, side, blockMetas);
} else if(side == 5)
{
b[0] = isConnected(world, x, y, z + 1, side, block, metas);
b[1] = isConnected(world, x, y, z - 1, side, block, metas);
b[2] = isConnected(world, x, y - 1, z, side, block, metas);
b[3] = isConnected(world, x, y + 1, z, side, block, metas);
b[0] = isConnected(world, x, y, z + 1, side, blockMetas);
b[1] = isConnected(world, x, y, z - 1, side, blockMetas);
b[2] = isConnected(world, x, y - 1, z, side, blockMetas);
b[3] = isConnected(world, x, y + 1, z, side, blockMetas);
}
if(b[0] & !b[1] & !b[2] & !b[3])
texture = 3;
@ -165,34 +163,34 @@ public class CTM
boolean b2[] = new boolean[6];
if(side <= 1)
{
b2[0] = !isConnected(world, x + 1, y, z + 1, side, block, metas);
b2[1] = !isConnected(world, x - 1, y, z + 1, side, block, metas);
b2[2] = !isConnected(world, x + 1, y, z - 1, side, block, metas);
b2[3] = !isConnected(world, x - 1, y, z - 1, side, block, metas);
b2[0] = !isConnected(world, x + 1, y, z + 1, side, blockMetas);
b2[1] = !isConnected(world, x - 1, y, z + 1, side, blockMetas);
b2[2] = !isConnected(world, x + 1, y, z - 1, side, blockMetas);
b2[3] = !isConnected(world, x - 1, y, z - 1, side, blockMetas);
} else if(side == 2)
{
b2[0] = !isConnected(world, x - 1, y - 1, z, side, block, metas);
b2[1] = !isConnected(world, x + 1, y - 1, z, side, block, metas);
b2[2] = !isConnected(world, x - 1, y + 1, z, side, block, metas);
b2[3] = !isConnected(world, x + 1, y + 1, z, side, block, metas);
b2[0] = !isConnected(world, x - 1, y - 1, z, side, blockMetas);
b2[1] = !isConnected(world, x + 1, y - 1, z, side, blockMetas);
b2[2] = !isConnected(world, x - 1, y + 1, z, side, blockMetas);
b2[3] = !isConnected(world, x + 1, y + 1, z, side, blockMetas);
} else if(side == 3)
{
b2[0] = !isConnected(world, x + 1, y - 1, z, side, block, metas);
b2[1] = !isConnected(world, x - 1, y - 1, z, side, block, metas);
b2[2] = !isConnected(world, x + 1, y + 1, z, side, block, metas);
b2[3] = !isConnected(world, x - 1, y + 1, z, side, block, metas);
b2[0] = !isConnected(world, x + 1, y - 1, z, side, blockMetas);
b2[1] = !isConnected(world, x - 1, y - 1, z, side, blockMetas);
b2[2] = !isConnected(world, x + 1, y + 1, z, side, blockMetas);
b2[3] = !isConnected(world, x - 1, y + 1, z, side, blockMetas);
} else if(side == 4)
{
b2[0] = !isConnected(world, x, y - 1, z + 1, side, block, metas);
b2[1] = !isConnected(world, x, y - 1, z - 1, side, block, metas);
b2[2] = !isConnected(world, x, y + 1, z + 1, side, block, metas);
b2[3] = !isConnected(world, x, y + 1, z - 1, side, block, metas);
b2[0] = !isConnected(world, x, y - 1, z + 1, side, blockMetas);
b2[1] = !isConnected(world, x, y - 1, z - 1, side, blockMetas);
b2[2] = !isConnected(world, x, y + 1, z + 1, side, blockMetas);
b2[3] = !isConnected(world, x, y + 1, z - 1, side, blockMetas);
} else if(side == 5)
{
b2[0] = !isConnected(world, x, y - 1, z - 1, side, block, metas);
b2[1] = !isConnected(world, x, y - 1, z + 1, side, block, metas);
b2[2] = !isConnected(world, x, y + 1, z - 1, side, block, metas);
b2[3] = !isConnected(world, x, y + 1, z + 1, side, block, metas);
b2[0] = !isConnected(world, x, y - 1, z - 1, side, blockMetas);
b2[1] = !isConnected(world, x, y - 1, z + 1, side, blockMetas);
b2[2] = !isConnected(world, x, y + 1, z - 1, side, blockMetas);
b2[3] = !isConnected(world, x, y + 1, z + 1, side, blockMetas);
}
if(texture == 17 && b2[0])
@ -269,7 +267,7 @@ public class CTM
return texture;
}
public static boolean isConnected(IBlockAccess world, int x, int y, int z, int side, Block block, List<Integer> metas)
public static boolean isConnected(IBlockAccess world, int x, int y, int z, int side, HashMap<Block, List<Integer>> blockMetas)
{
int x2 = x, y2 = y, z2 = z;
@ -295,12 +293,22 @@ public class CTM
break;
}
int meta = world.getBlockMetadata(x, y, z);
Block block1 = world.getBlock(x, y, z);
Block block2 = world.getBlock(x2, y2, z2);
int meta1 = world.getBlockMetadata(x, y, z);
int meta2 = world.getBlockMetadata(x2, y2, z2);
boolean validMeta = metas.contains(meta);
boolean validMeta2 = metas.contains(meta2);
boolean validBlockMeta1 = false;
boolean invalidBlockMeta2 = true;
return world.getBlock(x, y, z).equals(block) && validMeta && !(world.getBlock(x2, y2, z2).equals(block) && validMeta2);
for(Entry<Block, List<Integer>> entry : blockMetas.entrySet())
{
validBlockMeta1 |= block1.equals(entry.getKey()) && entry.getValue().contains(meta1);
invalidBlockMeta2 &= !(block2.equals(entry.getKey()) && entry.getValue().contains(meta2));
}
return validBlockMeta1 && invalidBlockMeta2;
}
}

View file

@ -43,7 +43,7 @@ public class CTMRenderingHandler implements ISimpleBlockRenderingHandler
rendererCTM.submap = blockCTM.submap;
rendererCTM.submapSmall = blockCTM.submapSmall;
rendererCTM.metas = blockCTM.acceptableMetas;
rendererCTM.blockMetas = blockCTM.acceptableBlockMetas;
rendererCTM.rendererOld = rendererOld;

View file

@ -1,5 +1,6 @@
package mekanism.client.render.block;
import java.util.HashMap;
import java.util.List;
import mekanism.client.render.CTM;
@ -37,7 +38,7 @@ public class RenderBlocksCTM extends RenderBlocks
TextureSubmap submap;
TextureSubmap submapSmall;
RenderBlocks rendererOld;
List<Integer> metas;
HashMap<Block, List<Integer>> blockMetas;
int bx, by, bz;
@ -152,7 +153,7 @@ public class RenderBlocksCTM extends RenderBlocks
tessellator.addVertexWithUV(0.0, 1.0, 1.0, i.getMaxU(), i.getMinV());
} else
{
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 4, metas);
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 4, blockMetas);
setupSides(1, 0, 4, 5, 14, 19, 17, 23, 9);
side(1, 14, 9, 23, tex[0], false);
@ -175,7 +176,7 @@ public class RenderBlocksCTM extends RenderBlocks
tessellator.addVertexWithUV(1.0, 1.0, 0.0, i.getMinU(), i.getMinV());
} else
{
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 5, metas);
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 5, blockMetas);
setupSides(3, 2, 6, 7, 15, 25, 16, 21, 11);
side(11, 21, 3, 15, tex[3], false);
@ -198,7 +199,7 @@ public class RenderBlocksCTM extends RenderBlocks
tessellator.addVertexWithUV(0.0, 1.0, 0.0, i.getMinU(), i.getMinV());
} else
{
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 2, metas);
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 2, blockMetas);
setupSides(2, 3, 0, 1, 15, 18, 14, 22, 8);
side(2, 15, 8, 22, tex[0], false);
@ -222,7 +223,7 @@ public class RenderBlocksCTM extends RenderBlocks
tessellator.addVertexWithUV(1.0, 1.0, 1.0, i.getMaxU(), i.getMinV());
} else
{
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 3, metas);
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 3, blockMetas);
setupSides(4, 7, 6, 5, 20, 16, 24, 17, 10);
side(17, 4, 20, 10, tex[2], false);
@ -245,7 +246,7 @@ public class RenderBlocksCTM extends RenderBlocks
tessellator.addVertexWithUV(1.0, 0.0, 1.0, i.getMaxU(), i.getMaxV());
} else
{
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 0, metas);
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 0, blockMetas);
setupSides(0, 3, 7, 4, 18, 21, 20, 19, 13);
side(13, 21, 7, 20, tex[3], true);
@ -268,7 +269,7 @@ public class RenderBlocksCTM extends RenderBlocks
tessellator.addVertexWithUV(1.0, 1.0, 0.0, i.getMaxU(), i.getMinV());
} else
{
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 1, metas);
int tex[] = CTM.getSubmapIndices(blockAccess, bx, by, bz, 1, blockMetas);
setupSides(2, 1, 5, 6, 22, 23, 24, 25, 12);
side(12, 24, 6, 25, tex[3], false);

View file

@ -1,6 +1,8 @@
package mekanism.common;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import mekanism.api.Coord4D;
import mekanism.client.render.block.TextureSubmap;
@ -22,26 +24,42 @@ public class CTMData
public String texture;
public List<Integer> acceptableMetas;
public HashMap<Block, List<Integer>> acceptableBlockMetas = new HashMap<Block, List<Integer>>();
public CTMData(String textureName, List<Integer> connectableMeta)
public CTMData(String textureName, Block block, List<Integer> connectableMeta)
{
texture = textureName;
acceptableMetas = connectableMeta;
acceptableBlockMetas.put(block, connectableMeta);
}
public void registerIcons(IIconRegister register)
public CTMData registerIcons(IIconRegister register)
{
icon = register.registerIcon("mekanism:" + texture);
submap = new TextureSubmap(register.registerIcon("mekanism:" + texture + "-ctm"), 4, 4);
submapSmall = new TextureSubmap(icon, 2, 2);
return this;
}
public CTMData addOtherBlockConnectivities(Block block, List<Integer> connectableMeta)
{
acceptableBlockMetas.put(block, connectableMeta);
return this;
}
@SideOnly(Side.CLIENT)
public boolean shouldRenderSide(IBlockAccess world, int x, int y, int z, int side, Block block)
public boolean shouldRenderSide(IBlockAccess world, int x, int y, int z, int side)
{
Coord4D obj = new Coord4D(x, y, z);
return !(obj.getBlock(world).equals(block) && acceptableMetas.contains(obj.getMetadata(world)));
Block coordBlock = obj.getBlock(world);
int coordMeta = obj.getMetadata(world);
boolean valid = false;
for(Entry<Block, List<Integer>> entry : acceptableBlockMetas.entrySet())
{
valid |= entry.getKey().equals(coordBlock) && entry.getValue().contains(coordMeta);
}
return !valid;
}
}

View file

@ -77,9 +77,7 @@ public class BlockBasic extends Block implements IBlockCTM
{
public IIcon[][] icons = new IIcon[256][6];
public CTMData dynamicTankCTM = new CTMData("ctm/DynamicTank", Arrays.asList(9, 11));
public CTMData dynamicGlassCTM = new CTMData("ctm/DynamicGlass",Arrays.asList(10));
public CTMData dynamicValveCTM = new CTMData("ctm/DynamicValve", Arrays.asList(11, 9));
public CTMData[] ctms = new CTMData[16];
public BlockBasic()
{
@ -137,13 +135,17 @@ public class BlockBasic extends Block implements IBlockCTM
icons[14][2] = register.registerIcon("mekanism:SalinationBlock");
icons[15][0] = register.registerIcon("mekanism:SalinationValve");
dynamicTankCTM.registerIcons(register);
dynamicGlassCTM.registerIcons(register);
dynamicValveCTM.registerIcons(register);
ctms[9] = new CTMData("ctm/DynamicTank", this, Arrays.asList(9, 11)).registerIcons(register);
ctms[10] = new CTMData("ctm/DynamicGlass", this, Arrays.asList(10)).registerIcons(register);
ctms[11] = new CTMData("ctm/DynamicValve", this, Arrays.asList(11, 9)).registerIcons(register);
ctms[15] = new CTMData("ctm/SalinationValve", this, Arrays.asList(15)).addOtherBlockConnectivities(MekanismBlocks.BasicBlock2, Arrays.asList(0)).registerIcons(register);
}
else if(this == MekanismBlocks.BasicBlock2)
{
icons[0][0] = register.registerIcon("mekanism:SalinationBlock");
ctms[0] = new CTMData("ctm/SalinationBlock", this, Arrays.asList(0)).addOtherBlockConnectivities(MekanismBlocks.BasicBlock, Arrays.asList(15)).registerIcons(register);
}
}
@ -173,11 +175,9 @@ public class BlockBasic extends Block implements IBlockCTM
return icons[6][0];
}
case 9:
return dynamicTankCTM.icon;
case 10:
return dynamicGlassCTM.icon;
case 11:
return dynamicValveCTM.icon;
return ctms[metadata].icon;
case 14:
TileEntitySalinationController tileEntity14 = (TileEntitySalinationController)world.getTileEntity(x, y, z);
@ -805,7 +805,7 @@ public class BlockBasic extends Block implements IBlockCTM
Coord4D obj = new Coord4D(x, y, z).getFromSide(ForgeDirection.getOrientation(side).getOpposite());
if(this == MekanismBlocks.BasicBlock && obj.getMetadata(world) == 10)
{
return dynamicGlassCTM.shouldRenderSide(world, x, y, z, side, this);
return ctms[10].shouldRenderSide(world, x, y, z, side);
}
else {
return super.shouldSideBeRendered(world, x, y, z, side);
@ -855,18 +855,6 @@ public class BlockBasic extends Block implements IBlockCTM
@Override
public CTMData getCTMData(int meta)
{
if(this == MekanismBlocks.BasicBlock)
{
switch(meta)
{
case 9:
return dynamicTankCTM;
case 10:
return dynamicGlassCTM;
case 11:
return dynamicValveCTM;
}
}
return null;
return ctms[meta];
}
}

View file

@ -46,9 +46,7 @@ public class BlockReactor extends BlockContainer implements IBlockCTM
{
public IIcon[][] icons = new IIcon[16][16];
public CTMData reactorGlassCTM = new CTMData("ctm/ReactorGlass", Arrays.asList(0, 1));
public CTMData reactorLaserFocusCTM = new CTMData("ctm/ReactorLaserFocus", Arrays.asList(1, 0));
public CTMData[] ctms = new CTMData[16];
public BlockReactor()
{
@ -76,8 +74,8 @@ public class BlockReactor extends BlockContainer implements IBlockCTM
icons[0][0] = register.registerIcon("mekanism:ReactorGlass");
icons[1][0] = register.registerIcon("mekanism:ReactorLaserFocus");
reactorGlassCTM.registerIcons(register);
reactorLaserFocusCTM.registerIcons(register);
ctms[0] = new CTMData("ctm/ReactorGlass", this, Arrays.asList(0, 1)).registerIcons(register);
ctms[1] = new CTMData("ctm/ReactorLaserFocus", this, Arrays.asList(1, 0)).registerIcons(register);
}
}
@ -304,17 +302,7 @@ public class BlockReactor extends BlockContainer implements IBlockCTM
@Override
public CTMData getCTMData(int meta)
{
if(this == GeneratorsBlocks.ReactorGlass)
{
switch(meta)
{
case 0:
return reactorGlassCTM;
case 1:
return reactorLaserFocusCTM;
}
}
return null;
return ctms[meta];
}
@Override
@ -324,12 +312,12 @@ public class BlockReactor extends BlockContainer implements IBlockCTM
Coord4D obj = new Coord4D(x, y, z).getFromSide(ForgeDirection.getOrientation(side).getOpposite());
if(this == GeneratorsBlocks.ReactorGlass)
{
switch(obj.getMetadata(world))
int metadata = obj.getMetadata(world);
switch(metadata)
{
case 0:
return reactorGlassCTM.shouldRenderSide(world, x, y, z, side, this);
case 1:
return reactorLaserFocusCTM.shouldRenderSide(world, x, y, z, side, this);
return ctms[metadata].shouldRenderSide(world, x, y, z, side);
default:
return super.shouldSideBeRendered(world, x, y, z, side);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 10
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB