Support for semi-transparent facades

This commit is contained in:
dmillerw 2014-04-09 21:53:59 -07:00
parent 1945458f97
commit c721982546
3 changed files with 148 additions and 130 deletions

View file

@ -8,14 +8,25 @@
*/ */
package buildcraft.transport; package buildcraft.transport;
import java.util.ArrayList; import buildcraft.BuildCraftTransport;
import java.util.Arrays; import buildcraft.api.gates.GateExpansions;
import java.util.HashMap; import buildcraft.api.gates.IGateExpansion;
import java.util.List; import buildcraft.api.tools.IToolWrench;
import java.util.Locale; import buildcraft.api.transport.PipeWire;
import java.util.Map; import buildcraft.core.*;
import java.util.Random; import buildcraft.core.robots.AIDocked;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.utils.BCLog;
import buildcraft.core.utils.MatrixTranformations;
import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.render.PipeRendererWorld;
import buildcraft.transport.utils.FacadeMatrix;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -37,28 +48,8 @@ import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.GateExpansions; import java.util.*;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.tools.IToolWrench;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.BlockIndex;
import buildcraft.core.CoreConstants;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemRobot;
import buildcraft.core.robots.AIDocked;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.utils.BCLog;
import buildcraft.core.utils.MatrixTranformations;
import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.utils.FacadeMatrix;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockGenericPipe extends BlockBuildCraft { public class BlockGenericPipe extends BlockBuildCraft {
@ -109,6 +100,17 @@ public class BlockGenericPipe extends BlockBuildCraft {
return TransportProxy.pipeModel; return TransportProxy.pipeModel;
} }
@Override
public boolean canRenderInPass(int pass) {
PipeRendererWorld.renderPass = pass;
return true;
}
@Override
public int getRenderBlockPass() {
return 1;
}
@Override @Override
public boolean isOpaqueCube() { public boolean isOpaqueCube() {
return false; return false;

View file

@ -92,79 +92,82 @@ public class FacadeRenderHelper {
Block renderBlock = state.facadeMatrix.getFacadeBlock(direction); Block renderBlock = state.facadeMatrix.getFacadeBlock(direction);
if (renderBlock != null) { if (renderBlock != null) {
int renderMeta = state.facadeMatrix.getFacadeMetaId(direction); // If the facade is meant to render in the current pass
if (renderBlock.canRenderInPass(PipeRendererWorld.renderPass)) {
int renderMeta = state.facadeMatrix.getFacadeMetaId(direction);
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
state.textureArray[side.ordinal()] = renderBlock.getIcon(side.ordinal(), renderMeta); state.textureArray[side.ordinal()] = renderBlock.getIcon(side.ordinal(), renderMeta);
if (side == direction || side == direction.getOpposite()) if (side == direction || side == direction.getOpposite())
block.setRenderSide(side, true); block.setRenderSide(side, true);
else else
block.setRenderSide(side, state.facadeMatrix.getFacadeBlock(side) == null); block.setRenderSide(side, state.facadeMatrix.getFacadeBlock(side) == null);
}
try {
BlockGenericPipe.facadeRenderColor = Item.getItemFromBlock(state.facadeMatrix.getFacadeBlock(direction)).getColorFromItemStack(new ItemStack(renderBlock, 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 try {
if (state.pipeConnectionMatrix.isConnected(direction)) { BlockGenericPipe.facadeRenderColor = Item.getItemFromBlock(state.facadeMatrix.getFacadeBlock(direction)).getColorFromItemStack(new ItemStack(renderBlock, 1, renderMeta), 0);
float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade); } catch (Throwable error) {
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); if (renderBlock.getRenderType() == 31) {
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4; if ((renderMeta & 12) == 4) {
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset * 4; renderblocks.uvRotateEast = 1;
rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2; renderblocks.uvRotateWest = 1;
MatrixTranformations.transform(rotated, direction); renderblocks.uvRotateTop = 1;
setRenderBounds(renderblocks, rotated, direction); renderblocks.uvRotateBottom = 1;
renderblocks.renderStandardBlock(block, x, y, z); } else if ((renderMeta & 12) == 8) {
renderblocks.uvRotateSouth = 1;
renderblocks.uvRotateNorth = 1;
}
}
rotated = MatrixTranformations.deepClone(zeroStateFacade); // Hollow facade
rotated[0][0] = 0.0F; if (state.pipeConnectionMatrix.isConnected(direction)) {
rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2; float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade);
MatrixTranformations.transform(rotated, direction); rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4;
setRenderBounds(renderblocks, rotated, direction); rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset * 4;
renderblocks.renderStandardBlock(block, x, y, z); 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 = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2; rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4;
rotated[0][1] = 1F; rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset * 4;
MatrixTranformations.transform(rotated, direction); rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2;
setRenderBounds(renderblocks, rotated, direction); MatrixTranformations.transform(rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z); setRenderBounds(renderblocks, rotated, direction);
} else { // Solid facade renderblocks.renderStandardBlock(block, x, y, z);
float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade);
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z);
}
if (renderBlock.getRenderType() == 31) { rotated = MatrixTranformations.deepClone(zeroStateFacade);
renderblocks.uvRotateSouth = 0; rotated[0][0] = 0.0F;
renderblocks.uvRotateEast = 0; rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2;
renderblocks.uvRotateWest = 0; MatrixTranformations.transform(rotated, direction);
renderblocks.uvRotateNorth = 0; setRenderBounds(renderblocks, rotated, direction);
renderblocks.uvRotateTop = 0; renderblocks.renderStandardBlock(block, x, y, z);
renderblocks.uvRotateBottom = 0;
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;
}
} }
} }
@ -176,13 +179,16 @@ public class FacadeRenderHelper {
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { // Always render connectors in pass 0
if (state.facadeMatrix.getFacadeBlock(direction) != null && !state.pipeConnectionMatrix.isConnected(direction)) { if (PipeRendererWorld.renderPass == 0) {
float[][] rotated = MatrixTranformations.deepClone(zeroStateSupport); for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
MatrixTranformations.transform(rotated, direction); if (state.facadeMatrix.getFacadeBlock(direction) != null && !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.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); renderblocks.renderStandardBlock(block, x, y, z);
}
} }
} }
} }

View file

@ -23,6 +23,8 @@ import net.minecraftforge.common.util.ForgeDirection;
public class PipeRendererWorld implements ISimpleBlockRenderingHandler { public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
public static int renderPass = -1;
public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, BlockGenericPipe block, TileGenericPipe tile, int x, int y, int z) { public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, BlockGenericPipe block, TileGenericPipe tile, int x, int y, int z) {
PipeRenderState state = tile.renderState; PipeRenderState state = tile.renderState;
IIconProvider icons = tile.getPipeIcons(); IIconProvider icons = tile.getPipeIcons();
@ -31,48 +33,56 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
return; return;
} }
int connectivity = state.pipeConnectionMatrix.getMask(); // Force pipe render into pass 0
float[] dim = new float[6]; if (renderPass == 0) {
int connectivity = state.pipeConnectionMatrix.getMask();
float[] dim = new float[6];
// render the unconnected pipe faces of the center block (if any) // render the unconnected pipe faces of the center block (if any)
if (connectivity != 0x3f) { // note: 0x3f = 0x111111 = all sides if (connectivity != 0x3f) { // note: 0x3f = 0x111111 = all sides
resetToCenterDimensions(dim); resetToCenterDimensions(dim);
state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN)); state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN));
renderTwoWayBlock(renderblocks, block, x, y, z, dim, connectivity ^ 0x3f); renderTwoWayBlock(renderblocks, block, x, y, z, dim, connectivity ^ 0x3f);
}
// render the connecting pipe faces
for (int dir = 0; dir < 6; dir++) {
int mask = 1 << dir;
if ((connectivity & mask) == 0) {
continue; // no connection towards dir
} }
// center piece offsets // render the connecting pipe faces
resetToCenterDimensions(dim);
// extend block towards dir as it's connected to there for (int dir = 0; dir < 6; dir++) {
dim[dir / 2] = dir % 2 == 0 ? 0 : CoreConstants.PIPE_MAX_POS; int mask = 1 << dir;
dim[dir / 2 + 3] = dir % 2 == 0 ? CoreConstants.PIPE_MIN_POS : 1;
// the mask points to all faces perpendicular to dir, i.e. dirs 0+1 -> mask 111100, 1+2 -> 110011, 3+5 -> 001111 if ((connectivity & mask) == 0) {
int renderMask = (3 << (dir / 2 * 2)) ^ 0x3f; continue; // no connection towards dir
}
// render sub block // center piece offsets
state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.VALID_DIRECTIONS[dir])); resetToCenterDimensions(dim);
renderTwoWayBlock(renderblocks, block, x, y, z, dim, renderMask); // extend block towards dir as it's connected to there
dim[dir / 2] = dir % 2 == 0 ? 0 : CoreConstants.PIPE_MAX_POS;
dim[dir / 2 + 3] = dir % 2 == 0 ? CoreConstants.PIPE_MIN_POS : 1;
// the mask points to all faces perpendicular to dir, i.e. dirs 0+1 -> mask 111100, 1+2 -> 110011, 3+5 -> 001111
int renderMask = (3 << (dir / 2 * 2)) ^ 0x3f;
// render sub block
state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.VALID_DIRECTIONS[dir]));
renderTwoWayBlock(renderblocks, block, x, y, z, dim, renderMask);
}
} }
renderblocks.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); renderblocks.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
// Facade renderer handles rendering in both passes
pipeFacadeRenderer(renderblocks, block, state, x, y, z); pipeFacadeRenderer(renderblocks, block, state, x, y, z);
pipePlugRenderer(renderblocks, block, state, x, y, z);
pipeRobotStationRenderer(renderblocks, block, state, x, y, z); // Force other opaque renders into pass 0
if (renderPass == 0) {
pipePlugRenderer(renderblocks, block, state, x, y, z);
pipeRobotStationRenderer(renderblocks, block, state, x, y, z);
}
} }
private void resetToCenterDimensions(float[] dim) { private void resetToCenterDimensions(float[] dim) {