More Facade Rendering tweaks

No, this does not fix #1287, sorry.
This commit is contained in:
CovertJaguar 2013-10-20 11:49:38 -07:00
parent 93f9dceb90
commit aa67b6dd5a
2 changed files with 204 additions and 154 deletions

View file

@ -0,0 +1,203 @@
/*
* Copyright (c) SpaceToad, 2011-2012
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.render;
import buildcraft.BuildCraftTransport;
import buildcraft.core.CoreConstants;
import buildcraft.core.utils.MatrixTranformations;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeRenderState;
import buildcraft.transport.TransportConstants;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class FacadeRenderHelper {
private static final float zFightOffset = 1F / 4096F;
private static final float[][] zeroStateFacade = new float[3][2];
private static final float[][] zeroStateSupport = new float[3][2];
private static final float[] xOffsets = new float[6];
private static final float[] yOffsets = new float[6];
private static final float[] zOffsets = new float[6];
static {
// X START - END
zeroStateFacade[0][0] = 0.0F;
zeroStateFacade[0][1] = 1.0F;
// Y START - END
zeroStateFacade[1][0] = 0.0F;
zeroStateFacade[1][1] = TransportConstants.FACADE_THICKNESS;
// Z START - END
zeroStateFacade[2][0] = 0.0F;
zeroStateFacade[2][1] = 1.0F;
// X START - END
zeroStateSupport[0][0] = CoreConstants.PIPE_MIN_POS;
zeroStateSupport[0][1] = CoreConstants.PIPE_MAX_POS;
// Y START - END
zeroStateSupport[1][0] = TransportConstants.FACADE_THICKNESS;
zeroStateSupport[1][1] = CoreConstants.PIPE_MIN_POS;
// Z START - END
zeroStateSupport[2][0] = CoreConstants.PIPE_MIN_POS;
zeroStateSupport[2][1] = CoreConstants.PIPE_MAX_POS;
xOffsets[0] = zFightOffset;
xOffsets[1] = zFightOffset;
xOffsets[2] = 0;
xOffsets[3] = 0;
xOffsets[4] = 0;
xOffsets[5] = 0;
yOffsets[0] = 0;
yOffsets[1] = 0;
yOffsets[2] = zFightOffset;
yOffsets[3] = zFightOffset;
yOffsets[4] = 0;
yOffsets[5] = 0;
zOffsets[0] = zFightOffset;
zOffsets[1] = zFightOffset;
zOffsets[2] = 0;
zOffsets[3] = 0;
zOffsets[4] = 0;
zOffsets[5] = 0;
}
private static void setRenderBounds(RenderBlocks renderblocks, float[][] rotated, ForgeDirection side) {
renderblocks.setRenderBounds(
rotated[0][0] + xOffsets[side.ordinal()],
rotated[1][0] + yOffsets[side.ordinal()],
rotated[2][0] + zOffsets[side.ordinal()],
rotated[0][1] - xOffsets[side.ordinal()],
rotated[1][1] - yOffsets[side.ordinal()],
rotated[2][1] - zOffsets[side.ordinal()]);
}
private static void setRenderBoundsAlt(RenderBlocks renderblocks, float[][] rotated, ForgeDirection side) {
renderblocks.setRenderBounds(
rotated[0][0],
rotated[1][0] + yOffsets[side.ordinal()],
rotated[2][0],
rotated[0][1],
rotated[1][1] + yOffsets[side.ordinal()],
rotated[2][1]);
}
public static void pipeFacadeRenderer(RenderBlocks renderblocks, BlockGenericPipe block, PipeRenderState state, int x, int y, int z) {
state.textureArray = new Icon[6];
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
int facadeId = state.facadeMatrix.getFacadeBlockId(direction);
if (facadeId != 0) {
Block renderBlock = Block.blocksList[facadeId];
int renderMeta = state.facadeMatrix.getFacadeMetaId(direction);
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
state.textureArray[side.ordinal()] = renderBlock.getIcon(side.ordinal(), renderMeta);
if (side == direction || side == direction.getOpposite())
block.setRenderSide(side, true);
else
block.setRenderSide(side, state.facadeMatrix.getFacadeBlockId(side) == 0);
}
try {
BlockGenericPipe.facadeRenderColor = Item.itemsList[state.facadeMatrix.getFacadeBlockId(direction)].getColorFromItemStack(new ItemStack(facadeId, 1, renderMeta), 0);
} catch (Throwable error) {
}
if (renderBlock.getRenderType() == 31) {
if ((renderMeta & 12) == 4) {
renderblocks.uvRotateEast = 1;
renderblocks.uvRotateWest = 1;
renderblocks.uvRotateTop = 1;
renderblocks.uvRotateBottom = 1;
} else if ((renderMeta & 12) == 8) {
renderblocks.uvRotateSouth = 1;
renderblocks.uvRotateNorth = 1;
}
}
// Hollow facade
if (state.pipeConnectionMatrix.isConnected(direction)) {
float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4;
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset * 4;
rotated[2][0] = 0.0F;
rotated[2][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2;
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4;
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset * 4;
rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2;
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = 0.0F;
rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2;
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2;
rotated[0][1] = 1F;
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z);
} else { // Solid facade
float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade);
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z);
}
if (renderBlock.getRenderType() == 31) {
renderblocks.uvRotateSouth = 0;
renderblocks.uvRotateEast = 0;
renderblocks.uvRotateWest = 0;
renderblocks.uvRotateNorth = 0;
renderblocks.uvRotateTop = 0;
renderblocks.uvRotateBottom = 0;
}
}
BlockGenericPipe.facadeRenderColor = -1;
}
state.textureArray = null;
block.setRenderAllSides();
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (state.facadeMatrix.getFacadeBlockId(direction) != 0 && !state.pipeConnectionMatrix.isConnected(direction)) {
float[][] rotated = MatrixTranformations.deepClone(zeroStateSupport);
MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z);
}
}
}
}

View file

@ -146,160 +146,7 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
}
private void pipeFacadeRenderer(RenderBlocks renderblocks, BlockGenericPipe block, PipeRenderState state, int x, int y, int z) {
float zFightOffset = 1F / 4096F;
float[][] zeroState = new float[3][2];
// X START - END
zeroState[0][0] = 0.0F;
zeroState[0][1] = 1.0F;
// Y START - END
zeroState[1][0] = 0.0F;
zeroState[1][1] = TransportConstants.FACADE_THICKNESS;
// Z START - END
zeroState[2][0] = 0.0F;
zeroState[2][1] = 1.0F;
float[] xOffsets = new float[6];
xOffsets[0] = zFightOffset;
xOffsets[1] = zFightOffset;
xOffsets[2] = 0;
xOffsets[3] = 0;
xOffsets[4] = 0;
xOffsets[5] = 0;
float[] yOffsets = new float[6];
yOffsets[0] = 0;
yOffsets[1] = 0;
yOffsets[2] = zFightOffset;
yOffsets[3] = zFightOffset;
yOffsets[4] = 0;
yOffsets[5] = 0;
float[] zOffsets = new float[6];
zOffsets[0] = zFightOffset;
zOffsets[1] = zFightOffset;
zOffsets[2] = 0;
zOffsets[3] = 0;
zOffsets[4] = 0;
zOffsets[5] = 0;
state.textureArray = new Icon[6];
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
int facadeId = state.facadeMatrix.getFacadeBlockId(direction);
if (facadeId != 0) {
Block renderBlock = Block.blocksList[facadeId];
int renderMeta = state.facadeMatrix.getFacadeMetaId(direction);
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
state.textureArray[side.ordinal()] = renderBlock.getIcon(side.ordinal(), renderMeta);
if (side == direction || side == direction.getOpposite())
block.setRenderSide(side, true);
else
block.setRenderSide(side, state.facadeMatrix.getFacadeBlockId(side) == 0);
}
try {
BlockGenericPipe.facadeRenderColor = Item.itemsList[state.facadeMatrix.getFacadeBlockId(direction)].getColorFromItemStack(new ItemStack(facadeId, 1, renderMeta), 0);
} catch (Throwable error) {
}
if (renderBlock.getRenderType() == 31) {
if ((renderMeta & 12) == 4) {
renderblocks.uvRotateEast = 1;
renderblocks.uvRotateWest = 1;
renderblocks.uvRotateTop = 1;
renderblocks.uvRotateBottom = 1;
} else if ((renderMeta & 12) == 8) {
renderblocks.uvRotateSouth = 1;
renderblocks.uvRotateNorth = 1;
}
}
// Hollow facade
if (state.pipeConnectionMatrix.isConnected(direction)) {
float[][] rotated = MatrixTranformations.deepClone(zeroState);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset;
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset;
rotated[2][0] = 0.0F;
rotated[2][1] = CoreConstants.PIPE_MIN_POS - zFightOffset;
MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z);
rotated = MatrixTranformations.deepClone(zeroState);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset;
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset;
rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset;
MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z);
rotated = MatrixTranformations.deepClone(zeroState);
rotated[0][0] = 0.0F;
rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset;
MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z);
rotated = MatrixTranformations.deepClone(zeroState);
rotated[0][0] = CoreConstants.PIPE_MAX_POS + zFightOffset;
rotated[0][1] = 1F;
MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z);
} else { // Solid facade
float[][] rotated = MatrixTranformations.deepClone(zeroState);
MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(
rotated[0][0] + xOffsets[direction.ordinal()],
rotated[1][0] + yOffsets[direction.ordinal()],
rotated[2][0] + zOffsets[direction.ordinal()],
rotated[0][1] + xOffsets[direction.ordinal()],
rotated[1][1] + yOffsets[direction.ordinal()],
rotated[2][1] + zOffsets[direction.ordinal()]);
renderblocks.renderStandardBlock(block, x, y, z);
}
if (renderBlock.getRenderType() == 31) {
renderblocks.uvRotateSouth = 0;
renderblocks.uvRotateEast = 0;
renderblocks.uvRotateWest = 0;
renderblocks.uvRotateNorth = 0;
renderblocks.uvRotateTop = 0;
renderblocks.uvRotateBottom = 0;
}
}
BlockGenericPipe.facadeRenderColor = -1;
}
state.textureArray = null;
block.setRenderAllSides();
// X START - END
zeroState[0][0] = CoreConstants.PIPE_MIN_POS;
zeroState[0][1] = CoreConstants.PIPE_MAX_POS;
// Y START - END
zeroState[1][0] = TransportConstants.FACADE_THICKNESS;
zeroState[1][1] = CoreConstants.PIPE_MIN_POS;
// Z START - END
zeroState[2][0] = CoreConstants.PIPE_MIN_POS;
zeroState[2][1] = CoreConstants.PIPE_MAX_POS;
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (state.facadeMatrix.getFacadeBlockId(direction) != 0 && !state.pipeConnectionMatrix.isConnected(direction)) {
float[][] rotated = MatrixTranformations.deepClone(zeroState);
MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z);
}
}
FacadeRenderHelper.pipeFacadeRenderer(renderblocks, block, state, x, y, z);
}
private void pipePlugRenderer(RenderBlocks renderblocks, Block block, PipeRenderState state, int x, int y, int z) {