Added color modifier support to Facades

This commit is contained in:
CovertJaguar 2013-06-30 23:21:55 -07:00
parent 8867512f38
commit 3cdcf094db
3 changed files with 226 additions and 204 deletions

View file

@ -1,12 +1,10 @@
/** /**
* Copyright (c) SpaceToad, 2011 * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
* http://www.mod-buildcraft.com
* *
* BuildCraft is distributed under the terms of the Minecraft Mod Public * BuildCraft is distributed under the terms of the Minecraft Mod Public License
* License 1.0, or MMPL. Please check the contents of the license located in * 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.transport; package buildcraft.transport;
import java.util.ArrayList; import java.util.ArrayList;
@ -51,27 +49,26 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
public class BlockGenericPipe extends BlockContainer { public class BlockGenericPipe extends BlockContainer {
static enum Part { static enum Part {
Pipe, Pipe,
Gate Gate
} }
static class RaytraceResult { static class RaytraceResult {
RaytraceResult(Part hitPart, MovingObjectPosition movingObjectPosition) { RaytraceResult(Part hitPart, MovingObjectPosition movingObjectPosition) {
this.hitPart = hitPart; this.hitPart = hitPart;
this.movingObjectPosition = movingObjectPosition; this.movingObjectPosition = movingObjectPosition;
} }
public Part hitPart; public Part hitPart;
public MovingObjectPosition movingObjectPosition; public MovingObjectPosition movingObjectPosition;
} }
private static Random rand = new Random(); private static Random rand = new Random();
private boolean skippedFirstIconRegister; private boolean skippedFirstIconRegister;
/* Defined subprograms ************************************************* */ /* Defined subprograms ************************************************* */
public BlockGenericPipe(int i) { public BlockGenericPipe(int i) {
super(i, Material.glass); super(i, Material.glass);
@ -290,7 +287,8 @@ public class BlockGenericPipe extends BlockContainer {
} }
/** /**
* pipe hits along x, y, and z axis, gate (all 6 sides) [and wires+facades] * pipe hits along x, y, and z axis, gate (all 6 sides) [and
* wires+facades]
*/ */
MovingObjectPosition[] hits = new MovingObjectPosition[]{null, null, null, null, null, null, null, null, null}; MovingObjectPosition[] hits = new MovingObjectPosition[]{null, null, null, null, null, null, null, null, null};
@ -390,7 +388,8 @@ public class BlockGenericPipe extends BlockContainer {
for (int i = 0; i < hits.length; i++) { for (int i = 0; i < hits.length; i++) {
MovingObjectPosition hit = hits[i]; MovingObjectPosition hit = hits[i];
if (hit == null) continue; if (hit == null)
continue;
double lengthSquared = hit.hitVec.squareDistanceTo(origin); double lengthSquared = hit.hitVec.squareDistanceTo(origin);
@ -503,6 +502,7 @@ public class BlockGenericPipe extends BlockContainer {
} }
return list; return list;
} }
public TileEntity createNewTileEntity(World var1) { public TileEntity createNewTileEntity(World var1) {
return new TileGenericPipe(); return new TileGenericPipe();
} }
@ -554,7 +554,6 @@ public class BlockGenericPipe extends BlockContainer {
} }
/* Wrappers ************************************************************ */ /* Wrappers ************************************************************ */
@Override @Override
public void onNeighborBlockChange(World world, int x, int y, int z, int l) { public void onNeighborBlockChange(World world, int x, int y, int z, int l) {
super.onNeighborBlockChange(world, x, y, z, l); super.onNeighborBlockChange(world, x, y, z, l);
@ -607,7 +606,6 @@ public class BlockGenericPipe extends BlockContainer {
return stripEquipment(pipe); return stripEquipment(pipe);
} else if (entityplayer.getCurrentEquippedItem() == null) { } else if (entityplayer.getCurrentEquippedItem() == null) {
// Fall through the end of the test // Fall through the end of the test
} else if (entityplayer.getCurrentEquippedItem().itemID == Item.sign.itemID) } else if (entityplayer.getCurrentEquippedItem().itemID == Item.sign.itemID)
// Sign will be placed anyway, so lets show the sign gui // Sign will be placed anyway, so lets show the sign gui
@ -694,7 +692,7 @@ public class BlockGenericPipe extends BlockContainer {
private boolean stripEquipment(Pipe pipe) { private boolean stripEquipment(Pipe pipe) {
// Try to strip wires first, starting with yellow. // Try to strip wires first, starting with yellow.
for (IPipe.WireColor color : IPipe.WireColor.values()) for (IPipe.WireColor color : IPipe.WireColor.values()) {
if (pipe.wireSet[color.reverse().ordinal()]) { if (pipe.wireSet[color.reverse().ordinal()]) {
if (!CoreProxy.proxy.isRenderWorld(pipe.worldObj)) { if (!CoreProxy.proxy.isRenderWorld(pipe.worldObj)) {
dropWire(color.reverse(), pipe.worldObj, pipe.xCoord, pipe.yCoord, pipe.zCoord); dropWire(color.reverse(), pipe.worldObj, pipe.xCoord, pipe.yCoord, pipe.zCoord);
@ -704,6 +702,7 @@ public class BlockGenericPipe extends BlockContainer {
pipe.container.scheduleRenderUpdate(); pipe.container.scheduleRenderUpdate();
return true; return true;
} }
}
// Try to strip gate next // Try to strip gate next
if (pipe.hasGate()) { if (pipe.hasGate()) {
@ -822,9 +821,7 @@ public class BlockGenericPipe extends BlockContainer {
} }
/* Registration ******************************************************** */ /* Registration ******************************************************** */
public static Map<Integer, Class<? extends Pipe>> pipes = new HashMap<Integer, Class<? extends Pipe>>(); public static Map<Integer, Class<? extends Pipe>> pipes = new HashMap<Integer, Class<? extends Pipe>>();
static long lastRemovedDate = -1; static long lastRemovedDate = -1;
public static Map<BlockIndex, Pipe> pipeRemoved = new HashMap<BlockIndex, Pipe>(); public static Map<BlockIndex, Pipe> pipeRemoved = new HashMap<BlockIndex, Pipe>();
@ -899,8 +896,7 @@ public class BlockGenericPipe extends BlockContainer {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) public void registerIcons(IconRegister iconRegister) {
{
if (!skippedFirstIconRegister) { if (!skippedFirstIconRegister) {
skippedFirstIconRegister = true; skippedFirstIconRegister = true;
return; return;
@ -940,7 +936,8 @@ public class BlockGenericPipe extends BlockContainer {
int z = target.blockZ; int z = target.blockZ;
Pipe pipe = getPipe(worldObj, x, y, z); Pipe pipe = getPipe(worldObj, x, y, z);
if (pipe == null) return false; if (pipe == null)
return false;
Icon icon = pipe.getIconProvider().getIcon(pipe.getIconIndexForItem()); Icon icon = pipe.getIconProvider().getIcon(pipe.getIconIndexForItem());
@ -1000,7 +997,8 @@ public class BlockGenericPipe extends BlockContainer {
@Override @Override
public boolean addBlockDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) { public boolean addBlockDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
Pipe pipe = getPipe(worldObj, x, y, z); Pipe pipe = getPipe(worldObj, x, y, z);
if (pipe == null) return false; if (pipe == null)
return false;
Icon icon = pipe.getIconProvider().getIcon(pipe.getIconIndexForItem()); Icon icon = pipe.getIconProvider().getIcon(pipe.getIconIndexForItem());
@ -1020,4 +1018,13 @@ public class BlockGenericPipe extends BlockContainer {
} }
return true; return true;
} }
public static int facadeRenderColor = -1;
@Override
public int colorMultiplier(IBlockAccess world, int x, int y, int z) {
if (facadeRenderColor != -1) {
return facadeRenderColor;
}
return super.colorMultiplier(world, x, y, z);
}
} }

View file

@ -13,6 +13,7 @@ import buildcraft.BuildCraftTransport;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.ItemFacade; import buildcraft.transport.ItemFacade;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import net.minecraft.item.Item;
public class FacadeItemRenderer implements IItemRenderer { public class FacadeItemRenderer implements IItemRenderer {
@ -21,6 +22,15 @@ public class FacadeItemRenderer implements IItemRenderer {
int decodedMeta = ItemFacade.getMetaData(item); int decodedMeta = ItemFacade.getMetaData(item);
int decodedBlockId = ItemFacade.getBlockId(item); int decodedBlockId = ItemFacade.getBlockId(item);
try {
int color = Item.itemsList[decodedBlockId].getColorFromItemStack(new ItemStack(decodedBlockId, 1, decodedMeta), 0);
float r = (float) (color >> 16 & 0xff) / 255F;
float g = (float) (color >> 8 & 0xff) / 255F;
float b = (float) (color & 0xff) / 255F;
GL11.glColor4f(r, g, b, 1.0F);
} catch (Throwable error) {
}
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
Block block = Block.blocksList[decodedBlockId]; Block block = Block.blocksList[decodedBlockId];
@ -134,5 +144,4 @@ public class FacadeItemRenderer implements IItemRenderer {
default: default:
} }
} }
} }

View file

@ -10,11 +10,14 @@ import buildcraft.api.core.IIconProvider;
import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipe.WireColor; import buildcraft.api.transport.IPipe.WireColor;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.IPipeRenderState; import buildcraft.transport.IPipeRenderState;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeRenderState; import buildcraft.transport.PipeRenderState;
import buildcraft.transport.TransportProxy; import buildcraft.transport.TransportProxy;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class PipeWorldRenderer implements ISimpleBlockRenderingHandler { public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
@ -32,11 +35,11 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
} }
/** /**
* Shifts the coordinates around effectivly rotating something. Zero state is DOWN then -> NORTH -> WEST Note - To obtain Pos, do a mirrorY() before * Shifts the coordinates around effectivly rotating something. Zero state
* is DOWN then -> NORTH -> WEST Note - To obtain Pos, do a mirrorY() before
* rotating * rotating
* *
* @param targetArray * @param targetArray the array that should be rotated
* the array that should be rotated
*/ */
private void rotate(float[][] targetArray) { private void rotate(float[][] targetArray) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@ -48,8 +51,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
} }
/** /**
* @param targetArray * @param targetArray the array that should be transformed
* the array that should be transformed
* @param direction * @param direction
*/ */
private void transform(float[][] targetArray, ForgeDirection direction) { private void transform(float[][] targetArray, ForgeDirection direction) {
@ -65,8 +67,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
/** /**
* Clones both dimensions of a float[][] * Clones both dimensions of a float[][]
* *
* @param source * @param source the float[][] to deepClone
* the float[][] to deepClone
* @return * @return
*/ */
private float[][] deepClone(float[][] source) { private float[][] deepClone(float[][] source) {
@ -84,7 +85,8 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
PipeRenderState state = renderState.getRenderState(); PipeRenderState state = renderState.getRenderState();
IIconProvider icons = renderState.getPipeIcons(); IIconProvider icons = renderState.getPipeIcons();
if (icons == null) return; if (icons == null)
return;
state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN)); state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN));
@ -182,21 +184,24 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
zeroState[2][1] = 1.0F; zeroState[2][1] = 1.0F;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (state.facadeMatrix.getFacadeBlockId(direction) != 0) { int facadeId = state.facadeMatrix.getFacadeBlockId(direction);
Block renderBlock = Block.blocksList[state.facadeMatrix.getFacadeBlockId(direction)]; if (facadeId != 0) {
Block renderBlock = Block.blocksList[facadeId];
int renderMeta = state.facadeMatrix.getFacadeMetaId(direction); int renderMeta = state.facadeMatrix.getFacadeMetaId(direction);
state.currentTexture = renderBlock.getIcon(direction.ordinal(), renderMeta); state.currentTexture = renderBlock.getIcon(direction.ordinal(), renderMeta);
try {
BlockGenericPipe.facadeRenderColor = Item.itemsList[state.facadeMatrix.getFacadeBlockId(direction)].getColorFromItemStack(new ItemStack(facadeId, 1, renderMeta), 0);
} catch (Throwable error) {
}
if (renderBlock.getRenderType() == 31) { if (renderBlock.getRenderType() == 31) {
if ((renderMeta & 12) == 4) if ((renderMeta & 12) == 4) {
{
renderblocks.uvRotateEast = 1; renderblocks.uvRotateEast = 1;
renderblocks.uvRotateWest = 1; renderblocks.uvRotateWest = 1;
renderblocks.uvRotateTop = 1; renderblocks.uvRotateTop = 1;
renderblocks.uvRotateBottom = 1; renderblocks.uvRotateBottom = 1;
} } else if ((renderMeta & 12) == 8) {
else if ((renderMeta & 12) == 8)
{
renderblocks.uvRotateSouth = 1; renderblocks.uvRotateSouth = 1;
renderblocks.uvRotateNorth = 1; renderblocks.uvRotateNorth = 1;
} }
@ -255,6 +260,8 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
renderblocks.uvRotateBottom = 0; renderblocks.uvRotateBottom = 0;
} }
} }
BlockGenericPipe.facadeRenderColor = -1;
} }
// X START - END // X START - END
@ -510,7 +517,6 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
@Override @Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override