Rewrote pipe world renderer to render from a state object instead of containing logic to calculate what to render. This state object can then be synced to the client to completely overwrite the client's view of the world

This commit is contained in:
Krapht 2012-07-12 05:56:07 +02:00
parent 6881db2406
commit 02b1e4ae35
11 changed files with 490 additions and 133 deletions

View file

@ -3,105 +3,95 @@ package net.minecraft.src.buildcraft.transport;
import net.minecraft.src.Block; import net.minecraft.src.Block;
import net.minecraft.src.IBlockAccess; import net.minecraft.src.IBlockAccess;
import net.minecraft.src.RenderBlocks; import net.minecraft.src.RenderBlocks;
import net.minecraft.src.TileEntity;
import net.minecraft.src.buildcraft.api.IPipe; import net.minecraft.src.buildcraft.api.IPipe;
import net.minecraft.src.buildcraft.api.Orientations; import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.IPipe.DrawingState; import net.minecraft.src.buildcraft.api.IPipe.WireColor;
import net.minecraft.src.buildcraft.core.DefaultProps; import net.minecraft.src.buildcraft.core.DefaultProps;
import net.minecraft.src.buildcraft.core.ITileBufferHolder;
import net.minecraft.src.buildcraft.core.Utils; import net.minecraft.src.buildcraft.core.Utils;
import net.minecraft.src.forge.MinecraftForgeClient; import net.minecraft.src.forge.MinecraftForgeClient;
public class PipeWorldRenderer { public class PipeWorldRenderer {
public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, TileEntity tile, Block block, PipeRenderState state) { public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, Block block, PipeRenderState state, int x, int y, int z) {
ITileBufferHolder holder = (ITileBufferHolder) tile;
float minSize = Utils.pipeMinPos; float minSize = Utils.pipeMinPos;
float maxSize = Utils.pipeMaxPos; float maxSize = Utils.pipeMaxPos;
IPipe pipe = ((TileGenericPipe)tile).pipe; MinecraftForgeClient.bindTexture(state.getTextureFile());
pipe.setDrawingState(DrawingState.DrawingPipe); state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.Unknown);
pipe.prepareTextureFor(Orientations.Unknown);
block.setBlockBounds(minSize, minSize, minSize, maxSize, maxSize, maxSize); block.setBlockBounds(minSize, minSize, minSize, maxSize, maxSize, maxSize);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
if (Utils.checkPipesConnections(tile, holder.getTile(Orientations.XNeg))) { if (state.pipeConnectionMatrix.isConnected(Orientations.XNeg)) {
pipe.prepareTextureFor(Orientations.XNeg); state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.XNeg);
block.setBlockBounds(0.0F, minSize, minSize, minSize, maxSize, maxSize); block.setBlockBounds(0.0F, minSize, minSize, minSize, maxSize, maxSize);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
if (Utils.checkPipesConnections(tile, holder.getTile(Orientations.XPos))) { if (state.pipeConnectionMatrix.isConnected(Orientations.XPos)) {
pipe.prepareTextureFor(Orientations.XPos); state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.XPos);
block.setBlockBounds(maxSize, minSize, minSize, 1.0F, maxSize, maxSize); block.setBlockBounds(maxSize, minSize, minSize, 1.0F, maxSize, maxSize);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
if (Utils.checkPipesConnections(tile, holder.getTile(Orientations.YNeg))) { if (state.pipeConnectionMatrix.isConnected(Orientations.YNeg)) {
pipe.prepareTextureFor(Orientations.YNeg); state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.YNeg);
block.setBlockBounds(minSize, 0.0F, minSize, maxSize, minSize, maxSize); block.setBlockBounds(minSize, 0.0F, minSize, maxSize, minSize, maxSize);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
if (Utils.checkPipesConnections(tile, holder.getTile(Orientations.YPos))) { if (state.pipeConnectionMatrix.isConnected(Orientations.YPos)) {
pipe.prepareTextureFor(Orientations.YPos); state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.YPos);
block.setBlockBounds(minSize, maxSize, minSize, maxSize, 1.0F, maxSize); block.setBlockBounds(minSize, maxSize, minSize, maxSize, 1.0F, maxSize);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
if (Utils.checkPipesConnections(tile, holder.getTile(Orientations.ZNeg))) { if (state.pipeConnectionMatrix.isConnected(Orientations.ZNeg)) {
pipe.prepareTextureFor(Orientations.ZNeg); state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.ZNeg);
block.setBlockBounds(minSize, minSize, 0.0F, maxSize, maxSize, minSize); block.setBlockBounds(minSize, minSize, 0.0F, maxSize, maxSize, minSize);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
if (Utils.checkPipesConnections(tile, holder.getTile(Orientations.ZPos))) { if (state.pipeConnectionMatrix.isConnected(Orientations.ZPos)) {
pipe.prepareTextureFor(Orientations.ZPos); state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.ZPos);
block.setBlockBounds(minSize, minSize, maxSize, maxSize, maxSize, 1.0F); block.setBlockBounds(minSize, minSize, maxSize, maxSize, maxSize, 1.0F);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
pipe.prepareTextureFor(Orientations.Unknown);
MinecraftForgeClient.bindTexture(DefaultProps.TEXTURE_BLOCKS); MinecraftForgeClient.bindTexture(DefaultProps.TEXTURE_BLOCKS);
if (pipe.isWired(IPipe.WireColor.Red)) { if (state.wireMatrix.hasWire(WireColor.Red)) {
pipe.setDrawingState(DrawingState.DrawingRedWire); state.currentTextureIndex = state.wireMatrix.getTextureIndex(WireColor.Red);
pipeRedstoneRender(renderblocks, iblockaccess, tile, pipe, block, Utils.pipeMinPos, Utils.pipeMaxPos, pipeWireRender(renderblocks, block, state, Utils.pipeMinPos, Utils.pipeMaxPos,
Utils.pipeMinPos, IPipe.WireColor.Red); Utils.pipeMinPos, IPipe.WireColor.Red, x, y, z);
} }
if (pipe.isWired(IPipe.WireColor.Blue)) { if (state.wireMatrix.hasWire(WireColor.Blue)) {
pipe.setDrawingState(DrawingState.DrawingBlueWire); state.currentTextureIndex = state.wireMatrix.getTextureIndex(WireColor.Blue);
pipeRedstoneRender(renderblocks, iblockaccess, tile, pipe, block, Utils.pipeMaxPos, Utils.pipeMaxPos, pipeWireRender(renderblocks, block, state, Utils.pipeMaxPos, Utils.pipeMaxPos,
Utils.pipeMaxPos, IPipe.WireColor.Blue); Utils.pipeMaxPos, IPipe.WireColor.Blue, x, y, z);
} }
if (pipe.isWired(IPipe.WireColor.Green)) { if (state.wireMatrix.hasWire(WireColor.Green)) {
pipe.setDrawingState(DrawingState.DrawingGreenWire); state.currentTextureIndex = state.wireMatrix.getTextureIndex(WireColor.Green);
pipeRedstoneRender(renderblocks, iblockaccess, tile, pipe, block, Utils.pipeMaxPos, Utils.pipeMinPos, pipeWireRender(renderblocks, block, state, Utils.pipeMaxPos, Utils.pipeMinPos,
Utils.pipeMinPos, IPipe.WireColor.Green); Utils.pipeMinPos, IPipe.WireColor.Green, x, y, z);
} }
if (pipe.isWired(IPipe.WireColor.Yellow)) { if (state.wireMatrix.hasWire(WireColor.Yellow)) {
pipe.setDrawingState(DrawingState.DrawingYellowWire); state.currentTextureIndex = state.wireMatrix.getTextureIndex(WireColor.Yellow);
pipeRedstoneRender(renderblocks, iblockaccess, tile, pipe, block, Utils.pipeMinPos, Utils.pipeMinPos, pipeWireRender(renderblocks, block, state, Utils.pipeMinPos, Utils.pipeMinPos,
Utils.pipeMaxPos, IPipe.WireColor.Yellow); Utils.pipeMaxPos, IPipe.WireColor.Yellow, x, y, z);
} }
if (pipe.hasInterface()) if (state.hasGate())
pipeInterfaceRender(renderblocks, iblockaccess, tile, pipe, block); pipeGateRender(renderblocks, block, state, x, y, z);
} }
private void pipeRedstoneRender(RenderBlocks renderblocks, IBlockAccess iblockaccess, TileEntity tile, IPipe pipe, private void pipeWireRender(RenderBlocks renderblocks, Block block, PipeRenderState state, float cx, float cy, float cz, IPipe.WireColor color, int x, int y, int z) {
Block block, float cx, float cy, float cz, IPipe.WireColor color) {
ITileBufferHolder holder = (ITileBufferHolder) tile;
float minX = Utils.pipeMinPos; float minX = Utils.pipeMinPos;
float minY = Utils.pipeMinPos; float minY = Utils.pipeMinPos;
@ -113,32 +103,32 @@ public class PipeWorldRenderer {
boolean foundX = false, foundY = false, foundZ = false; boolean foundX = false, foundY = false, foundZ = false;
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.XNeg), color)) { if (state.wireMatrix.isWireConnected(color, Orientations.XNeg)) {
minX = 0; minX = 0;
foundX = true; foundX = true;
} }
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.XPos), color)) { if (state.wireMatrix.isWireConnected(color, Orientations.XPos)) {
maxX = 1; maxX = 1;
foundX = true; foundX = true;
} }
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.YNeg), color)) { if (state.wireMatrix.isWireConnected(color, Orientations.YNeg)) {
minY = 0; minY = 0;
foundY = true; foundY = true;
} }
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.YPos), color)) { if (state.wireMatrix.isWireConnected(color, Orientations.YPos)) {
maxY = 1; maxY = 1;
foundY = true; foundY = true;
} }
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.ZNeg), color)) { if (state.wireMatrix.isWireConnected(color, Orientations.ZNeg)) {
minZ = 0; minZ = 0;
foundZ = true; foundZ = true;
} }
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.ZPos), color)) { if (state.wireMatrix.isWireConnected(color, Orientations.ZPos)) {
maxZ = 1; maxZ = 1;
foundZ = true; foundZ = true;
} }
@ -189,7 +179,7 @@ public class PipeWorldRenderer {
block.setBlockBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, cy == Utils.pipeMinPos ? cy - 0.05F : cy, minZ, block.setBlockBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, cy == Utils.pipeMinPos ? cy - 0.05F : cy, minZ,
cx == Utils.pipeMinPos ? cx : cx + 0.05F, cy == Utils.pipeMinPos ? cy : cy + 0.05F, maxZ); cx == Utils.pipeMinPos ? cx : cx + 0.05F, cy == Utils.pipeMinPos ? cy : cy + 0.05F, maxZ);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
// X render // X render
@ -198,7 +188,7 @@ public class PipeWorldRenderer {
block.setBlockBounds(minX, cy == Utils.pipeMinPos ? cy - 0.05F : cy, cz == Utils.pipeMinPos ? cz - 0.05F : cz, maxX, block.setBlockBounds(minX, cy == Utils.pipeMinPos ? cy - 0.05F : cy, cz == Utils.pipeMinPos ? cz - 0.05F : cz, maxX,
cy == Utils.pipeMinPos ? cy : cy + 0.05F, cz == Utils.pipeMinPos ? cz : cz + 0.05F); cy == Utils.pipeMinPos ? cy : cy + 0.05F, cz == Utils.pipeMinPos ? cz : cz + 0.05F);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
// Y render // Y render
@ -207,7 +197,7 @@ public class PipeWorldRenderer {
block.setBlockBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, minY, cz == Utils.pipeMinPos ? cz - 0.05F : cz, block.setBlockBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, minY, cz == Utils.pipeMinPos ? cz - 0.05F : cz,
cx == Utils.pipeMinPos ? cx : cx + 0.05F, maxY, cz == Utils.pipeMinPos ? cz : cz + 0.05F); cx == Utils.pipeMinPos ? cx : cx + 0.05F, maxY, cz == Utils.pipeMinPos ? cz : cz + 0.05F);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
if (center || !found) { if (center || !found) {
@ -215,58 +205,46 @@ public class PipeWorldRenderer {
cz == Utils.pipeMinPos ? cz - 0.05F : cz, cx == Utils.pipeMinPos ? cx : cx + 0.05F, cz == Utils.pipeMinPos ? cz - 0.05F : cz, cx == Utils.pipeMinPos ? cx : cx + 0.05F,
cy == Utils.pipeMinPos ? cy : cy + 0.05F, cz == Utils.pipeMinPos ? cz : cz + 0.05F); cy == Utils.pipeMinPos ? cy : cy + 0.05F, cz == Utils.pipeMinPos ? cz : cz + 0.05F);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord); renderblocks.renderStandardBlock(block, x, y, z);
} }
} }
private boolean isConnectedWiredPipe(IPipe pipe, TileEntity tile2, IPipe.WireColor color) { private void pipeGateRender(RenderBlocks renderblocks, Block block, PipeRenderState state, int x, int y, int z) {
return pipe.isWireConnectedTo(tile2, color);
}
private void pipeInterfaceRender(RenderBlocks renderblocks, IBlockAccess iblockaccess, TileEntity tile, IPipe pipe, Block block) {
ITileBufferHolder holder = (ITileBufferHolder) tile; state.currentTextureIndex = state.getGateTextureIndex();
pipe.setDrawingState(DrawingState.DrawingGate);
float min = Utils.pipeMinPos + 0.05F; float min = Utils.pipeMinPos + 0.05F;
float max = Utils.pipeMaxPos - 0.05F; float max = Utils.pipeMaxPos - 0.05F;
if (!Utils.checkPipesConnections(tile, holder.getTile(Orientations.XNeg))) { if (!state.pipeConnectionMatrix.isConnected(Orientations.XNeg)) {
block.setBlockBounds(Utils.pipeMinPos - 0.10F, min, min, Utils.pipeMinPos, max, max); block.setBlockBounds(Utils.pipeMinPos - 0.10F, min, min, Utils.pipeMinPos, max, max);
renderblocks.renderStandardBlock(block, x, y, z);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord);
} }
if (!Utils.checkPipesConnections(tile, holder.getTile(Orientations.XPos))) { if (!state.pipeConnectionMatrix.isConnected(Orientations.XPos)) {
block.setBlockBounds(Utils.pipeMaxPos, min, min, Utils.pipeMaxPos + 0.10F, max, max); block.setBlockBounds(Utils.pipeMaxPos, min, min, Utils.pipeMaxPos + 0.10F, max, max);
renderblocks.renderStandardBlock(block, x, y, z);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord);
} }
if (!Utils.checkPipesConnections(tile, holder.getTile(Orientations.YNeg))) { if (!state.pipeConnectionMatrix.isConnected(Orientations.YNeg)) {
block.setBlockBounds(min, Utils.pipeMinPos - 0.10F, min, max, Utils.pipeMinPos, max); block.setBlockBounds(min, Utils.pipeMinPos - 0.10F, min, max, Utils.pipeMinPos, max);
renderblocks.renderStandardBlock(block, x, y, z);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord);
} }
if (!Utils.checkPipesConnections(tile, holder.getTile(Orientations.YPos))) { if (!state.pipeConnectionMatrix.isConnected(Orientations.YPos)) {
block.setBlockBounds(min, Utils.pipeMaxPos, min, max, Utils.pipeMaxPos + 0.10F, max); block.setBlockBounds(min, Utils.pipeMaxPos, min, max, Utils.pipeMaxPos + 0.10F, max);
renderblocks.renderStandardBlock(block, x, y, z);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord);
} }
if (!Utils.checkPipesConnections(tile, holder.getTile(Orientations.ZNeg))) { if (!state.pipeConnectionMatrix.isConnected(Orientations.ZNeg)) {
block.setBlockBounds(min, min, Utils.pipeMinPos - 0.10F, max, max, Utils.pipeMinPos); block.setBlockBounds(min, min, Utils.pipeMinPos - 0.10F, max, max, Utils.pipeMinPos);
renderblocks.renderStandardBlock(block, x, y, z);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord);
} }
if (!Utils.checkPipesConnections(tile, holder.getTile(Orientations.ZPos))) { if (!state.pipeConnectionMatrix.isConnected(Orientations.ZPos)) {
block.setBlockBounds(min, min, Utils.pipeMaxPos, max, max, Utils.pipeMaxPos + 0.10F); block.setBlockBounds(min, min, Utils.pipeMaxPos, max, max, Utils.pipeMaxPos + 0.10F);
renderblocks.renderStandardBlock(block, x, y, z);
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord);
} }
} }
} }

View file

@ -9,12 +9,12 @@
package net.minecraft.src; package net.minecraft.src;
import net.minecraft.src.buildcraft.api.IPipeTile;
import net.minecraft.src.buildcraft.core.DefaultProps; import net.minecraft.src.buildcraft.core.DefaultProps;
import net.minecraft.src.buildcraft.transport.IPipeRenderState; import net.minecraft.src.buildcraft.transport.IPipeRenderState;
import net.minecraft.src.buildcraft.transport.PipeItemRenderer; import net.minecraft.src.buildcraft.transport.PipeItemRenderer;
import net.minecraft.src.buildcraft.transport.PipeWorldRenderer; import net.minecraft.src.buildcraft.transport.PipeWorldRenderer;
import net.minecraft.src.buildcraft.transport.RenderPipe; import net.minecraft.src.buildcraft.transport.RenderPipe;
import net.minecraft.src.buildcraft.transport.TileGenericPipe;
import net.minecraft.src.forge.MinecraftForgeClient; import net.minecraft.src.forge.MinecraftForgeClient;
import net.minecraft.src.forge.NetworkMod; import net.minecraft.src.forge.NetworkMod;
@ -90,8 +90,9 @@ public class mod_BuildCraftTransport extends NetworkMod {
TileEntity tile = world.getBlockTileEntity(x, y, z); TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof IPipeRenderState){ if (tile instanceof TileGenericPipe){
pipeWorldRenderer.renderPipe(renderer, world, tile, block, ((IPipeRenderState)tile).getRenderState()); TileGenericPipe pipeTile = (TileGenericPipe) tile;
pipeWorldRenderer.renderPipe(renderer, world, block, ((IPipeRenderState)tile).getRenderState(), pipeTile.xCoord, pipeTile.yCoord, pipeTile.zCoord);
} }
// if (tile != null && tile instanceof IPipeTile && ((IPipeTile)tile).isInitialized()) { // if (tile != null && tile instanceof IPipeTile && ((IPipeTile)tile).isInitialized()) {
// pipeWorldRenderer.renderPipe(renderer, world, tile, block); // pipeWorldRenderer.renderPipe(renderer, world, tile, block);

View file

@ -16,4 +16,6 @@ public class PacketIds {
public static final int GATE_SELECTION_CHANGE = 44; public static final int GATE_SELECTION_CHANGE = 44;
public static final int GATE_TRIGGERS = 45; public static final int GATE_TRIGGERS = 45;
public static final int REFINERY_FILTER_SET = 50; public static final int REFINERY_FILTER_SET = 50;
public static final int PIPE_RENDER_STATE = 60;
} }

View file

@ -254,10 +254,10 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
/** Wrappers *************************************************************/ /** Wrappers *************************************************************/
@Override @Override
public void onNeighborBlockChange(World world, int i, int j, int k, int l) { public void onNeighborBlockChange(World world, int x, int y, int z, int l) {
super.onNeighborBlockChange(world, i, j, k, l); super.onNeighborBlockChange(world, x, y, z, l);
Pipe pipe = getPipe(world, i, j, k); Pipe pipe = getPipe(world, x, y, z);
if (isValid(pipe)) if (isValid(pipe))
pipe.container.scheduleNeighborChange(); pipe.container.scheduleNeighborChange();
@ -272,7 +272,7 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
if (isValid(pipe)) if (isValid(pipe))
pipe.onBlockPlaced(); pipe.onBlockPlaced();
} }
@Override @Override
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer) { public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer) {
super.blockActivated(world, i, j, k, entityplayer); super.blockActivated(world, i, j, k, entityplayer);
@ -305,7 +305,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
if (!pipe.wireSet[IPipe.WireColor.Red.ordinal()]) { if (!pipe.wireSet[IPipe.WireColor.Red.ordinal()]) {
pipe.wireSet[IPipe.WireColor.Red.ordinal()] = true; pipe.wireSet[IPipe.WireColor.Red.ordinal()] = true;
entityplayer.getCurrentEquippedItem().splitStack(1); entityplayer.getCurrentEquippedItem().splitStack(1);
world.markBlockNeedsUpdate(i, j, k); pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true; return true;
} }
@ -313,7 +314,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
if (!pipe.wireSet[IPipe.WireColor.Blue.ordinal()]) { if (!pipe.wireSet[IPipe.WireColor.Blue.ordinal()]) {
pipe.wireSet[IPipe.WireColor.Blue.ordinal()] = true; pipe.wireSet[IPipe.WireColor.Blue.ordinal()] = true;
entityplayer.getCurrentEquippedItem().splitStack(1); entityplayer.getCurrentEquippedItem().splitStack(1);
world.markBlockNeedsUpdate(i, j, k); pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true; return true;
} }
@ -321,7 +323,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
if (!pipe.wireSet[IPipe.WireColor.Green.ordinal()]) { if (!pipe.wireSet[IPipe.WireColor.Green.ordinal()]) {
pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true; pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true;
entityplayer.getCurrentEquippedItem().splitStack(1); entityplayer.getCurrentEquippedItem().splitStack(1);
world.markBlockNeedsUpdate(i, j, k); pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true; return true;
} }
@ -329,7 +332,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
if (!pipe.wireSet[IPipe.WireColor.Yellow.ordinal()]) { if (!pipe.wireSet[IPipe.WireColor.Yellow.ordinal()]) {
pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true; pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true;
entityplayer.getCurrentEquippedItem().splitStack(1); entityplayer.getCurrentEquippedItem().splitStack(1);
world.markBlockNeedsUpdate(i, j, k); pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true; return true;
} }
@ -339,7 +343,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
pipe.gate = new GateVanilla(pipe, entityplayer.getCurrentEquippedItem()); pipe.gate = new GateVanilla(pipe, entityplayer.getCurrentEquippedItem());
entityplayer.getCurrentEquippedItem().splitStack(1); entityplayer.getCurrentEquippedItem().splitStack(1);
world.markBlockNeedsUpdate(i, j, k); pipe.container.scheduleRenderUpdate();
//world.markBlockNeedsUpdate(i, j, k);
return true; return true;
} }
@ -363,7 +368,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
if (!APIProxy.isRemote()) if (!APIProxy.isRemote())
dropWire(color.reverse(), pipe.worldObj, pipe.xCoord, pipe.yCoord, pipe.zCoord); dropWire(color.reverse(), pipe.worldObj, pipe.xCoord, pipe.yCoord, pipe.zCoord);
pipe.wireSet[color.reverse().ordinal()] = false; pipe.wireSet[color.reverse().ordinal()] = false;
pipe.worldObj.markBlockNeedsUpdate(pipe.xCoord, pipe.yCoord, pipe.zCoord); //pipe.worldObj.markBlockNeedsUpdate(pipe.xCoord, pipe.yCoord, pipe.zCoord);
pipe.container.scheduleRenderUpdate();
return true; return true;
} }
@ -403,6 +409,9 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
} }
/**
* Used by the legacyPipeRenderer
*/
@Override @Override
public void prepareTextureFor(IBlockAccess blockAccess, int i, int j, int k, Orientations connection) { public void prepareTextureFor(IBlockAccess blockAccess, int i, int j, int k, Orientations connection) {
Pipe pipe = getPipe(blockAccess, i, j, k); Pipe pipe = getPipe(blockAccess, i, j, k);
@ -413,18 +422,24 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
@SuppressWarnings({ "all" }) @SuppressWarnings({ "all" })
public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l) { public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l) {
Pipe pipe = getPipe(iblockaccess, i, j, k);
if (!isValid(pipe)) { TileEntity tile = iblockaccess.getBlockTileEntity(i, j, k);
CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS); if (!(tile instanceof IPipeRenderState)) return 0;
return 0; return ((IPipeRenderState)tile).getRenderState().currentTextureIndex;
}
int pipeTexture = pipe.getPipeTexture();
if (pipeTexture > 255) { // Pipe pipe = getPipe(iblockaccess, i, j, k);
CoreProxy.BindTexture(DefaultProps.TEXTURE_EXTERNAL); // if (!isValid(pipe)) {
return pipeTexture - 256; // CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
} // return 0;
CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS); // }
return pipeTexture; // int pipeTexture = pipe.getPipeTexture();
// if (pipeTexture > 255) {
// CoreProxy.BindTexture(DefaultProps.TEXTURE_EXTERNAL);
// return pipeTexture - 256;
// }
// CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
// return pipeTexture;
} }
@Override @Override

View file

@ -295,7 +295,9 @@ public class Pipe implements IPipe, IDropControlInventory {
if (!foundBiggerSignal && signalStrength[color.ordinal()] != 0) { if (!foundBiggerSignal && signalStrength[color.ordinal()] != 0) {
signalStrength[color.ordinal()] = 0; signalStrength[color.ordinal()] = 0;
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); //worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
container.scheduleRenderUpdate();
for (Orientations o : Orientations.dirs()) { for (Orientations o : Orientations.dirs()) {
TileEntity tile = container.getTile(o); TileEntity tile = container.getTile(o);
@ -352,8 +354,11 @@ public class Pipe implements IPipe, IDropControlInventory {
signalStrength[color.ordinal()] = signal; signalStrength[color.ordinal()] = signal;
internalUpdateScheduled = true; internalUpdateScheduled = true;
if (oldSignal == 0) if (oldSignal == 0) {
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); //worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
container.scheduleRenderUpdate();
}
return true; return true;
} else } else
@ -432,9 +437,11 @@ public class Pipe implements IPipe, IDropControlInventory {
public void randomDisplayTick(Random random) {} public void randomDisplayTick(Random random) {}
@Deprecated
private DrawingState drawingState = DrawingState.DrawingPipe; private DrawingState drawingState = DrawingState.DrawingPipe;
@Override @Override
@Deprecated
public void setDrawingState(DrawingState state) { public void setDrawingState(DrawingState state) {
drawingState = state; drawingState = state;
} }
@ -537,8 +544,9 @@ public class Pipe implements IPipe, IDropControlInventory {
activatedActions = new Action[activatedActions.length]; activatedActions = new Action[activatedActions.length];
broadcastSignal = new boolean[] { false, false, false, false }; broadcastSignal = new boolean[] { false, false, false, false };
broadcastRedstone = false; broadcastRedstone = false;
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); //worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, BuildCraftTransport.genericPipeBlock.blockID); container.scheduleRenderUpdate();
//worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, BuildCraftTransport.genericPipeBlock.blockID);
} }
private void resolveActions() { private void resolveActions() {
@ -594,13 +602,15 @@ public class Pipe implements IPipe, IDropControlInventory {
actionsActivated(actions); actionsActivated(actions);
if (oldBroadcastRedstone != broadcastRedstone) { if (oldBroadcastRedstone != broadcastRedstone) {
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); container.scheduleRenderUpdate();
//worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, BuildCraftTransport.genericPipeBlock.blockID); worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, BuildCraftTransport.genericPipeBlock.blockID);
} }
for (int i = 0; i < oldBroadcastSignal.length; ++i) for (int i = 0; i < oldBroadcastSignal.length; ++i)
if (oldBroadcastSignal[i] != broadcastSignal[i]) { if (oldBroadcastSignal[i] != broadcastSignal[i]) {
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); //worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
container.scheduleRenderUpdate();
updateSignalState(); updateSignalState();
break; break;
} }
@ -667,4 +677,11 @@ public class Pipe implements IPipe, IDropControlInventory {
public boolean doDrop() { public boolean doDrop() {
return logic.doDrop(); return logic.doDrop();
} }
public boolean isGateActive(){
for (boolean b : broadcastSignal){
if (b) return true;
}
return broadcastRedstone;
}
} }

View file

@ -1,10 +1,89 @@
package net.minecraft.src.buildcraft.transport; package net.minecraft.src.buildcraft.transport;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.src.buildcraft.core.DefaultProps;
import net.minecraft.src.buildcraft.transport.utils.ConnectionMatrix; import net.minecraft.src.buildcraft.transport.utils.ConnectionMatrix;
import net.minecraft.src.buildcraft.transport.utils.TextureMatrix;
import net.minecraft.src.buildcraft.transport.utils.WireMatrix;
public class PipeRenderState { public class PipeRenderState {
public ConnectionMatrix pipeConnection = new ConnectionMatrix(); private String textureFile = DefaultProps.TEXTURE_BLOCKS;
private boolean hasGate = false;
private int gateTextureIndex = 0;
public final ConnectionMatrix pipeConnectionMatrix = new ConnectionMatrix();
public final TextureMatrix textureMatrix = new TextureMatrix();
public final WireMatrix wireMatrix = new WireMatrix();
private boolean dirty = false;
/**This is a placeholder for the pipe renderer to set to a value that the BlockGenericPipe->TileGenericPipe will
* then return the the WorldRenderer
*/
public int currentTextureIndex;
public void setTextureFile(String textureFile){
if (this.textureFile != textureFile){
this.textureFile = textureFile;
this.dirty = true;
}
}
public String getTextureFile(){
return this.textureFile;
}
public void setHasGate(boolean value){
if (hasGate != value){
hasGate = value;
dirty = true;
}
}
public boolean hasGate(){
return hasGate;
}
public void setGateTexture(int value){
if (gateTextureIndex != value){
gateTextureIndex = value;
dirty = true;
}
}
public int getGateTextureIndex(){
return gateTextureIndex;
}
public void clean(){
dirty = false;
pipeConnectionMatrix.clean();
textureMatrix.clean();
wireMatrix.clean();
}
public boolean isDirty(){
return dirty || pipeConnectionMatrix.isDirty() || textureMatrix.isDirty() || wireMatrix.isDirty();
}
public void writeData(DataOutputStream data) throws IOException {
data.writeUTF(textureFile);
pipeConnectionMatrix.writeData(data);
textureMatrix.writeData(data);
wireMatrix.writeData(data);
}
public void readData(DataInputStream data) throws IOException {
textureFile = data.readUTF();
pipeConnectionMatrix.readData(data);
textureMatrix.readData(data);
wireMatrix.readData(data);
}
} }

View file

@ -13,8 +13,6 @@ import java.util.LinkedList;
import net.minecraft.src.BuildCraftCore; import net.minecraft.src.BuildCraftCore;
import net.minecraft.src.BuildCraftTransport; import net.minecraft.src.BuildCraftTransport;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound; import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.Packet; import net.minecraft.src.Packet;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
@ -24,11 +22,11 @@ import net.minecraft.src.buildcraft.api.EntityPassiveItem;
import net.minecraft.src.buildcraft.api.ILiquidContainer; import net.minecraft.src.buildcraft.api.ILiquidContainer;
import net.minecraft.src.buildcraft.api.IOverrideDefaultTriggers; import net.minecraft.src.buildcraft.api.IOverrideDefaultTriggers;
import net.minecraft.src.buildcraft.api.IPipe; import net.minecraft.src.buildcraft.api.IPipe;
import net.minecraft.src.buildcraft.api.IPipe.WireColor;
import net.minecraft.src.buildcraft.api.IPipeConnection; import net.minecraft.src.buildcraft.api.IPipeConnection;
import net.minecraft.src.buildcraft.api.IPipeEntry; import net.minecraft.src.buildcraft.api.IPipeEntry;
import net.minecraft.src.buildcraft.api.IPipeTile; import net.minecraft.src.buildcraft.api.IPipeTile;
import net.minecraft.src.buildcraft.api.IPowerReceptor; import net.minecraft.src.buildcraft.api.IPowerReceptor;
import net.minecraft.src.buildcraft.api.ISpecialInventory;
import net.minecraft.src.buildcraft.api.LiquidSlot; import net.minecraft.src.buildcraft.api.LiquidSlot;
import net.minecraft.src.buildcraft.api.Orientations; import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.api.Position; import net.minecraft.src.buildcraft.api.Position;
@ -36,6 +34,7 @@ import net.minecraft.src.buildcraft.api.PowerProvider;
import net.minecraft.src.buildcraft.api.SafeTimeTracker; import net.minecraft.src.buildcraft.api.SafeTimeTracker;
import net.minecraft.src.buildcraft.api.TileNetworkData; import net.minecraft.src.buildcraft.api.TileNetworkData;
import net.minecraft.src.buildcraft.api.Trigger; import net.minecraft.src.buildcraft.api.Trigger;
import net.minecraft.src.buildcraft.api.IPipe.DrawingState;
import net.minecraft.src.buildcraft.core.CoreProxy; import net.minecraft.src.buildcraft.core.CoreProxy;
import net.minecraft.src.buildcraft.core.DefaultProps; import net.minecraft.src.buildcraft.core.DefaultProps;
import net.minecraft.src.buildcraft.core.IDropControlInventory; import net.minecraft.src.buildcraft.core.IDropControlInventory;
@ -47,6 +46,8 @@ import net.minecraft.src.buildcraft.core.network.PacketPayload;
import net.minecraft.src.buildcraft.core.network.PacketPipeDescription; import net.minecraft.src.buildcraft.core.network.PacketPipeDescription;
import net.minecraft.src.buildcraft.core.network.PacketTileUpdate; import net.minecraft.src.buildcraft.core.network.PacketTileUpdate;
import net.minecraft.src.buildcraft.core.network.PacketUpdate; import net.minecraft.src.buildcraft.core.network.PacketUpdate;
import net.minecraft.src.buildcraft.transport.network.PipeRenderStatePacket;
import net.minecraft.src.buildcraft.transport.utils.WireMatrix;
public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiquidContainer, IPipeEntry, public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiquidContainer, IPipeEntry,
IPipeTile, ISynchronizedTile, IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory, IPipeRenderState { IPipeTile, ISynchronizedTile, IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory, IPipeRenderState {
@ -60,8 +61,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
public Pipe pipe; public Pipe pipe;
private boolean blockNeighborChange = false; private boolean blockNeighborChange = false;
private boolean refreshRenderState = false;
private boolean pipeBound = false; private boolean pipeBound = false;
//Store the pipe key to prevent losing pipes when a user forgets to include an addon //Store the pipe key to prevent losing pipes when a user forgets to include an addon
int key; int key;
@ -137,6 +139,12 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
computeConnections(); computeConnections();
pipe.onNeighborBlockChange(0); pipe.onNeighborBlockChange(0);
blockNeighborChange = false; blockNeighborChange = false;
refreshRenderState = true;
}
if (refreshRenderState){
refreshRenderState();
refreshRenderState = false;
} }
PowerProvider provider = getPowerProvider(); PowerProvider provider = getPowerProvider();
@ -148,6 +156,69 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
pipe.updateEntity(); pipe.updateEntity();
} }
//PRECONDITION: worldObj must not be null
private void refreshRenderState() {
//Only done on server/SSP
if (worldObj.isRemote) return;
// Pipe connections;
for(Orientations o : Orientations.dirs()){
renderState.pipeConnectionMatrix.setConnected(o, this.pipeConnectionsBuffer[o.ordinal()]);
}
// Pipe Textures
for(Orientations o: Orientations.values()){
pipe.prepareTextureFor(o);
renderState.textureMatrix.setTextureIndex(o, pipe.getMainBlockTexture());
}
// WireState
for (IPipe.WireColor color : IPipe.WireColor.values()){
renderState.wireMatrix.setWire(color, pipe.wireSet[color.ordinal()]);
for (Orientations direction : Orientations.dirs()){
renderState.wireMatrix.setWireConnected(color, direction, pipe.isWireConnectedTo(this.getTile(direction), color));
}
}
// Wire Textures
if (pipe.wireSet[IPipe.WireColor.Red.ordinal()]) {
renderState.wireMatrix.setTextureIndex(WireColor.Red, pipe.signalStrength[IPipe.WireColor.Red.ordinal()] > 0 ? 6 : 5);
} else {
renderState.wireMatrix.setTextureIndex(WireColor.Red, 0);
}
if (pipe.wireSet[IPipe.WireColor.Blue.ordinal()]) {
renderState.wireMatrix.setTextureIndex(WireColor.Blue, pipe.signalStrength[IPipe.WireColor.Blue.ordinal()] > 0 ? 8 : 7);
} else {
renderState.wireMatrix.setTextureIndex(WireColor.Blue, 0);
}
if (pipe.wireSet[IPipe.WireColor.Green.ordinal()]) {
renderState.wireMatrix.setTextureIndex(WireColor.Green, pipe.signalStrength[IPipe.WireColor.Green.ordinal()] > 0 ? 10 : 9);
} else {
renderState.wireMatrix.setTextureIndex(WireColor.Green, 0);
}
if (pipe.wireSet[IPipe.WireColor.Yellow.ordinal()]) {
renderState.wireMatrix.setTextureIndex(WireColor.Yellow, pipe.signalStrength[IPipe.WireColor.Yellow.ordinal()] > 0 ? 12 : 11);
} else {
renderState.wireMatrix.setTextureIndex(WireColor.Yellow, 0);
}
// Gate Textures
renderState.setHasGate(pipe.hasGate());
renderState.setGateTexture(!pipe.hasGate()?0:pipe.gate.getTexture(pipe.isGateActive()));
if (renderState.isDirty()){
//worldObj.markBlockAsNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);
worldObj.markBlockNeedsUpdate(this.xCoord, this.yCoord, this.zCoord);
renderState.clean();
}
}
public void initialize(Pipe pipe) { public void initialize(Pipe pipe) {
this.pipe = pipe; this.pipe = pipe;
@ -172,6 +243,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
bindPipe(); bindPipe();
computeConnections(); computeConnections();
refreshRenderState = true;
if (pipe != null) if (pipe != null)
pipe.initialize(); pipe.initialize();
@ -277,7 +350,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
*/ */
@Override @Override
public void handleDescriptionPacket(PacketUpdate packet) { public void handleDescriptionPacket(PacketUpdate packet) {
if (pipe == null && packet.payload.intPayload[0] != 0) { if (pipe == null && packet.payload.intPayload[0] != 0) {
initialize(BlockGenericPipe.createPipe(packet.payload.intPayload[0])); initialize(BlockGenericPipe.createPipe(packet.payload.intPayload[0]));
@ -415,7 +488,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
if (oldConnections[i] != pipeConnectionsBuffer[i]) { if (oldConnections[i] != pipeConnectionsBuffer[i]) {
Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[i]); Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[i]);
pos.moveForwards(1.0); pos.moveForwards(1.0);
worldObj.markBlockAsNeedsUpdate((int) pos.x, (int) pos.y, (int) pos.z); scheduleRenderUpdate();
//worldObj.markBlockAsNeedsUpdate((int) pos.x, (int) pos.y, (int) pos.z);
} }
} }
} }
@ -433,6 +507,11 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
return false; return false;
} }
public void scheduleRenderUpdate(){
refreshRenderState = true;
}
/** IPipeRenderState implementation **/ /** IPipeRenderState implementation **/
@Override @Override

View file

@ -0,0 +1,36 @@
package net.minecraft.src.buildcraft.transport.network;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.src.buildcraft.core.network.PacketCoordinates;
import net.minecraft.src.buildcraft.core.network.PacketIds;
import net.minecraft.src.buildcraft.transport.PipeRenderState;
public class PipeRenderStatePacket extends PacketCoordinates {
private PipeRenderState renderState;
public PipeRenderStatePacket(PipeRenderState renderState, int x, int y, int z) {
super(PacketIds.PIPE_RENDER_STATE, x, y, z);
this.renderState = renderState;
}
@Override
public void writeData(DataOutputStream data) throws IOException {
renderState.writeData(data);
}
@Override
public void readData(DataInputStream data) throws IOException {
renderState.readData(data);
}
@Override
public int getID() {
return PacketIds.PIPE_RENDER_STATE;
}
}

View file

@ -1,23 +1,45 @@
package net.minecraft.src.buildcraft.transport.utils; package net.minecraft.src.buildcraft.transport.utils;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.src.buildcraft.api.Orientations; import net.minecraft.src.buildcraft.api.Orientations;
public class ConnectionMatrix { public class ConnectionMatrix {
private final boolean[] _connected = new boolean[Orientations.dirs().length]; private final boolean[] _connected = new boolean[Orientations.dirs().length];
public void reset(){ private boolean dirty = false;
for (int i = 0; i < Orientations.dirs().length; i++){
_connected[i] = false;
}
}
public boolean isConnected(Orientations direction){ public boolean isConnected(Orientations direction){
return _connected[direction.ordinal()]; return _connected[direction.ordinal()];
} }
public void setConnected(Orientations direction, boolean value){ public void setConnected(Orientations direction, boolean value){
_connected[direction.ordinal()] = value; if (_connected[direction.ordinal()] != value){
_connected[direction.ordinal()] = value;
dirty = true;
}
} }
public boolean isDirty() {
return dirty;
}
public void clean() {
dirty = false;
}
public void writeData(DataOutputStream data) throws IOException {
for(int i = 0; i < Orientations.dirs().length; i++){
data.writeBoolean(_connected[i]);
}
}
public void readData(DataInputStream data) throws IOException {
for (int i = 0; i < Orientations.dirs().length; i++){
_connected[i] = data.readBoolean();
}
}
} }

View file

@ -0,0 +1,45 @@
package net.minecraft.src.buildcraft.transport.utils;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.src.buildcraft.api.Orientations;
public class TextureMatrix {
private final int[] _textureIndexes = new int[Orientations.values().length];
private boolean dirty = false;
public int getTextureIndex(Orientations direction){
return _textureIndexes[direction.ordinal()];
}
public void setTextureIndex(Orientations direction, int value){
if (_textureIndexes[direction.ordinal()] != value){
_textureIndexes[direction.ordinal()] = value;
dirty = true;
}
}
public boolean isDirty() {
return dirty;
}
public void clean() {
dirty = false;
}
public void writeData(DataOutputStream data) throws IOException {
for(int i = 0; i < Orientations.dirs().length; i++){
data.writeInt(_textureIndexes[i]);
}
}
public void readData(DataInputStream data) throws IOException {
for (int i = 0; i < Orientations.dirs().length; i++){
_textureIndexes[i] = data.readInt();
}
}
}

View file

@ -0,0 +1,83 @@
package net.minecraft.src.buildcraft.transport.utils;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.src.buildcraft.api.IPipe;
import net.minecraft.src.buildcraft.api.Orientations;
public class WireMatrix {
private final boolean[] _hasWire = new boolean[IPipe.WireColor.values().length];
private final ConnectionMatrix _wires[] = new ConnectionMatrix[IPipe.WireColor.values().length];
private int _wireTextureIndex[] = new int[IPipe.WireColor.values().length];
private boolean dirty = false;
public WireMatrix(){
for (int i = 0; i < IPipe.WireColor.values().length; i++){
_wires[i] = new ConnectionMatrix();
}
}
public boolean hasWire(IPipe.WireColor color){
return _hasWire[color.ordinal()];
}
public void setWire(IPipe.WireColor color, boolean value){
if (_hasWire[color.ordinal()] != value){
_hasWire[color.ordinal()] = value;
dirty = true;
}
}
public boolean isWireConnected(IPipe.WireColor color, Orientations direction){
return _wires[color.ordinal()].isConnected(direction);
}
public void setWireConnected(IPipe.WireColor color, Orientations direction, boolean value){
_wires[color.ordinal()].setConnected(direction, value);
}
public int getTextureIndex(IPipe.WireColor color){
return _wireTextureIndex[color.ordinal()];
}
public void setTextureIndex(IPipe.WireColor color, int value){
if (_wireTextureIndex[color.ordinal()] != value){
_wireTextureIndex[color.ordinal()] = value;
dirty = true;
}
}
public boolean isDirty() {
for (int i = 0; i < IPipe.WireColor.values().length; i++){
if (_wires[i].isDirty()) return true;
}
return dirty;
}
public void clean() {
for (int i = 0; i < IPipe.WireColor.values().length; i++){
_wires[i].clean();
}
dirty = false;
}
public void writeData(DataOutputStream data) throws IOException {
for (int i = 0; i < IPipe.WireColor.values().length; i++){
data.writeBoolean(_hasWire[i]);
_wires[i].writeData(data);
}
}
public void readData(DataInputStream data) throws IOException {
for (int i = 0; i < IPipe.WireColor.values().length; i++){
_hasWire[i] = data.readBoolean();
_wires[i].readData(data);
}
}
}