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:
parent
19c4de5a1c
commit
8365d1ca35
11 changed files with 490 additions and 133 deletions
|
@ -3,105 +3,95 @@ package net.minecraft.src.buildcraft.transport;
|
|||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.IBlockAccess;
|
||||
import net.minecraft.src.RenderBlocks;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.buildcraft.api.IPipe;
|
||||
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.ITileBufferHolder;
|
||||
import net.minecraft.src.buildcraft.core.Utils;
|
||||
import net.minecraft.src.forge.MinecraftForgeClient;
|
||||
|
||||
public class PipeWorldRenderer {
|
||||
|
||||
public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, TileEntity tile, Block block, PipeRenderState state) {
|
||||
|
||||
ITileBufferHolder holder = (ITileBufferHolder) tile;
|
||||
public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, Block block, PipeRenderState state, int x, int y, int z) {
|
||||
|
||||
float minSize = Utils.pipeMinPos;
|
||||
float maxSize = Utils.pipeMaxPos;
|
||||
|
||||
IPipe pipe = ((TileGenericPipe)tile).pipe;
|
||||
MinecraftForgeClient.bindTexture(state.getTextureFile());
|
||||
|
||||
pipe.setDrawingState(DrawingState.DrawingPipe);
|
||||
|
||||
pipe.prepareTextureFor(Orientations.Unknown);
|
||||
state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.Unknown);
|
||||
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))) {
|
||||
pipe.prepareTextureFor(Orientations.XNeg);
|
||||
if (state.pipeConnectionMatrix.isConnected(Orientations.XNeg)) {
|
||||
state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.XNeg);
|
||||
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))) {
|
||||
pipe.prepareTextureFor(Orientations.XPos);
|
||||
if (state.pipeConnectionMatrix.isConnected(Orientations.XPos)) {
|
||||
state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.XPos);
|
||||
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))) {
|
||||
pipe.prepareTextureFor(Orientations.YNeg);
|
||||
if (state.pipeConnectionMatrix.isConnected(Orientations.YNeg)) {
|
||||
state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.YNeg);
|
||||
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))) {
|
||||
pipe.prepareTextureFor(Orientations.YPos);
|
||||
if (state.pipeConnectionMatrix.isConnected(Orientations.YPos)) {
|
||||
state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.YPos);
|
||||
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))) {
|
||||
pipe.prepareTextureFor(Orientations.ZNeg);
|
||||
if (state.pipeConnectionMatrix.isConnected(Orientations.ZNeg)) {
|
||||
state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.ZNeg);
|
||||
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))) {
|
||||
pipe.prepareTextureFor(Orientations.ZPos);
|
||||
if (state.pipeConnectionMatrix.isConnected(Orientations.ZPos)) {
|
||||
state.currentTextureIndex = state.textureMatrix.getTextureIndex(Orientations.ZPos);
|
||||
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);
|
||||
|
||||
pipe.prepareTextureFor(Orientations.Unknown);
|
||||
MinecraftForgeClient.bindTexture(DefaultProps.TEXTURE_BLOCKS);
|
||||
|
||||
if (pipe.isWired(IPipe.WireColor.Red)) {
|
||||
pipe.setDrawingState(DrawingState.DrawingRedWire);
|
||||
pipeRedstoneRender(renderblocks, iblockaccess, tile, pipe, block, Utils.pipeMinPos, Utils.pipeMaxPos,
|
||||
Utils.pipeMinPos, IPipe.WireColor.Red);
|
||||
if (state.wireMatrix.hasWire(WireColor.Red)) {
|
||||
state.currentTextureIndex = state.wireMatrix.getTextureIndex(WireColor.Red);
|
||||
pipeWireRender(renderblocks, block, state, Utils.pipeMinPos, Utils.pipeMaxPos,
|
||||
Utils.pipeMinPos, IPipe.WireColor.Red, x, y, z);
|
||||
}
|
||||
|
||||
if (pipe.isWired(IPipe.WireColor.Blue)) {
|
||||
pipe.setDrawingState(DrawingState.DrawingBlueWire);
|
||||
pipeRedstoneRender(renderblocks, iblockaccess, tile, pipe, block, Utils.pipeMaxPos, Utils.pipeMaxPos,
|
||||
Utils.pipeMaxPos, IPipe.WireColor.Blue);
|
||||
if (state.wireMatrix.hasWire(WireColor.Blue)) {
|
||||
state.currentTextureIndex = state.wireMatrix.getTextureIndex(WireColor.Blue);
|
||||
pipeWireRender(renderblocks, block, state, Utils.pipeMaxPos, Utils.pipeMaxPos,
|
||||
Utils.pipeMaxPos, IPipe.WireColor.Blue, x, y, z);
|
||||
}
|
||||
|
||||
if (pipe.isWired(IPipe.WireColor.Green)) {
|
||||
pipe.setDrawingState(DrawingState.DrawingGreenWire);
|
||||
pipeRedstoneRender(renderblocks, iblockaccess, tile, pipe, block, Utils.pipeMaxPos, Utils.pipeMinPos,
|
||||
Utils.pipeMinPos, IPipe.WireColor.Green);
|
||||
if (state.wireMatrix.hasWire(WireColor.Green)) {
|
||||
state.currentTextureIndex = state.wireMatrix.getTextureIndex(WireColor.Green);
|
||||
pipeWireRender(renderblocks, block, state, Utils.pipeMaxPos, Utils.pipeMinPos,
|
||||
Utils.pipeMinPos, IPipe.WireColor.Green, x, y, z);
|
||||
}
|
||||
|
||||
if (pipe.isWired(IPipe.WireColor.Yellow)) {
|
||||
pipe.setDrawingState(DrawingState.DrawingYellowWire);
|
||||
pipeRedstoneRender(renderblocks, iblockaccess, tile, pipe, block, Utils.pipeMinPos, Utils.pipeMinPos,
|
||||
Utils.pipeMaxPos, IPipe.WireColor.Yellow);
|
||||
if (state.wireMatrix.hasWire(WireColor.Yellow)) {
|
||||
state.currentTextureIndex = state.wireMatrix.getTextureIndex(WireColor.Yellow);
|
||||
pipeWireRender(renderblocks, block, state, Utils.pipeMinPos, Utils.pipeMinPos,
|
||||
Utils.pipeMaxPos, IPipe.WireColor.Yellow, x, y, z);
|
||||
}
|
||||
|
||||
if (pipe.hasInterface())
|
||||
pipeInterfaceRender(renderblocks, iblockaccess, tile, pipe, block);
|
||||
if (state.hasGate())
|
||||
pipeGateRender(renderblocks, block, state, x, y, z);
|
||||
}
|
||||
|
||||
private void pipeRedstoneRender(RenderBlocks renderblocks, IBlockAccess iblockaccess, TileEntity tile, IPipe pipe,
|
||||
Block block, float cx, float cy, float cz, IPipe.WireColor color) {
|
||||
|
||||
ITileBufferHolder holder = (ITileBufferHolder) tile;
|
||||
private void pipeWireRender(RenderBlocks renderblocks, Block block, PipeRenderState state, float cx, float cy, float cz, IPipe.WireColor color, int x, int y, int z) {
|
||||
|
||||
float minX = Utils.pipeMinPos;
|
||||
float minY = Utils.pipeMinPos;
|
||||
|
@ -113,32 +103,32 @@ public class PipeWorldRenderer {
|
|||
|
||||
boolean foundX = false, foundY = false, foundZ = false;
|
||||
|
||||
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.XNeg), color)) {
|
||||
if (state.wireMatrix.isWireConnected(color, Orientations.XNeg)) {
|
||||
minX = 0;
|
||||
foundX = true;
|
||||
}
|
||||
|
||||
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.XPos), color)) {
|
||||
if (state.wireMatrix.isWireConnected(color, Orientations.XPos)) {
|
||||
maxX = 1;
|
||||
foundX = true;
|
||||
}
|
||||
|
||||
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.YNeg), color)) {
|
||||
if (state.wireMatrix.isWireConnected(color, Orientations.YNeg)) {
|
||||
minY = 0;
|
||||
foundY = true;
|
||||
}
|
||||
|
||||
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.YPos), color)) {
|
||||
if (state.wireMatrix.isWireConnected(color, Orientations.YPos)) {
|
||||
maxY = 1;
|
||||
foundY = true;
|
||||
}
|
||||
|
||||
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.ZNeg), color)) {
|
||||
if (state.wireMatrix.isWireConnected(color, Orientations.ZNeg)) {
|
||||
minZ = 0;
|
||||
foundZ = true;
|
||||
}
|
||||
|
||||
if (isConnectedWiredPipe(pipe, holder.getTile(Orientations.ZPos), color)) {
|
||||
if (state.wireMatrix.isWireConnected(color, Orientations.ZPos)) {
|
||||
maxZ = 1;
|
||||
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,
|
||||
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
|
||||
|
@ -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,
|
||||
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
|
||||
|
@ -207,7 +197,7 @@ public class PipeWorldRenderer {
|
|||
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);
|
||||
|
||||
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
renderblocks.renderStandardBlock(block, x, y, z);
|
||||
}
|
||||
|
||||
if (center || !found) {
|
||||
|
@ -215,58 +205,46 @@ public class PipeWorldRenderer {
|
|||
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);
|
||||
|
||||
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) {
|
||||
return pipe.isWireConnectedTo(tile2, color);
|
||||
}
|
||||
private void pipeGateRender(RenderBlocks renderblocks, Block block, PipeRenderState state, int x, int y, int z) {
|
||||
|
||||
private void pipeInterfaceRender(RenderBlocks renderblocks, IBlockAccess iblockaccess, TileEntity tile, IPipe pipe, Block block) {
|
||||
|
||||
ITileBufferHolder holder = (ITileBufferHolder) tile;
|
||||
|
||||
pipe.setDrawingState(DrawingState.DrawingGate);
|
||||
state.currentTextureIndex = state.getGateTextureIndex();
|
||||
|
||||
float min = Utils.pipeMinPos + 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);
|
||||
|
||||
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)) {
|
||||
block.setBlockBounds(Utils.pipeMaxPos, min, min, Utils.pipeMaxPos + 0.10F, max, max);
|
||||
|
||||
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)) {
|
||||
block.setBlockBounds(min, Utils.pipeMinPos - 0.10F, min, max, Utils.pipeMinPos, max);
|
||||
|
||||
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)) {
|
||||
block.setBlockBounds(min, Utils.pipeMaxPos, min, max, Utils.pipeMaxPos + 0.10F, max);
|
||||
|
||||
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)) {
|
||||
block.setBlockBounds(min, min, Utils.pipeMinPos - 0.10F, max, max, Utils.pipeMinPos);
|
||||
|
||||
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)) {
|
||||
block.setBlockBounds(min, min, Utils.pipeMaxPos, max, max, Utils.pipeMaxPos + 0.10F);
|
||||
|
||||
renderblocks.renderStandardBlock(block, tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
renderblocks.renderStandardBlock(block, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
package net.minecraft.src;
|
||||
|
||||
import net.minecraft.src.buildcraft.api.IPipeTile;
|
||||
import net.minecraft.src.buildcraft.core.DefaultProps;
|
||||
import net.minecraft.src.buildcraft.transport.IPipeRenderState;
|
||||
import net.minecraft.src.buildcraft.transport.PipeItemRenderer;
|
||||
import net.minecraft.src.buildcraft.transport.PipeWorldRenderer;
|
||||
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.NetworkMod;
|
||||
|
||||
|
@ -90,8 +90,9 @@ public class mod_BuildCraftTransport extends NetworkMod {
|
|||
|
||||
TileEntity tile = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof IPipeRenderState){
|
||||
pipeWorldRenderer.renderPipe(renderer, world, tile, block, ((IPipeRenderState)tile).getRenderState());
|
||||
if (tile instanceof TileGenericPipe){
|
||||
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()) {
|
||||
// pipeWorldRenderer.renderPipe(renderer, world, tile, block);
|
||||
|
|
|
@ -16,4 +16,6 @@ public class PacketIds {
|
|||
public static final int GATE_SELECTION_CHANGE = 44;
|
||||
public static final int GATE_TRIGGERS = 45;
|
||||
public static final int REFINERY_FILTER_SET = 50;
|
||||
|
||||
public static final int PIPE_RENDER_STATE = 60;
|
||||
}
|
||||
|
|
|
@ -254,10 +254,10 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
/** Wrappers *************************************************************/
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int i, int j, int k, int l) {
|
||||
super.onNeighborBlockChange(world, i, j, k, l);
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int 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))
|
||||
pipe.container.scheduleNeighborChange();
|
||||
|
@ -305,7 +305,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
if (!pipe.wireSet[IPipe.WireColor.Red.ordinal()]) {
|
||||
pipe.wireSet[IPipe.WireColor.Red.ordinal()] = true;
|
||||
entityplayer.getCurrentEquippedItem().splitStack(1);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
pipe.container.scheduleRenderUpdate();
|
||||
//world.markBlockNeedsUpdate(i, j, k);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -313,7 +314,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
if (!pipe.wireSet[IPipe.WireColor.Blue.ordinal()]) {
|
||||
pipe.wireSet[IPipe.WireColor.Blue.ordinal()] = true;
|
||||
entityplayer.getCurrentEquippedItem().splitStack(1);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
pipe.container.scheduleRenderUpdate();
|
||||
//world.markBlockNeedsUpdate(i, j, k);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -321,7 +323,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
if (!pipe.wireSet[IPipe.WireColor.Green.ordinal()]) {
|
||||
pipe.wireSet[IPipe.WireColor.Green.ordinal()] = true;
|
||||
entityplayer.getCurrentEquippedItem().splitStack(1);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
pipe.container.scheduleRenderUpdate();
|
||||
//world.markBlockNeedsUpdate(i, j, k);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -329,7 +332,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
if (!pipe.wireSet[IPipe.WireColor.Yellow.ordinal()]) {
|
||||
pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] = true;
|
||||
entityplayer.getCurrentEquippedItem().splitStack(1);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
pipe.container.scheduleRenderUpdate();
|
||||
//world.markBlockNeedsUpdate(i, j, k);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -339,7 +343,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
|
||||
pipe.gate = new GateVanilla(pipe, entityplayer.getCurrentEquippedItem());
|
||||
entityplayer.getCurrentEquippedItem().splitStack(1);
|
||||
world.markBlockNeedsUpdate(i, j, k);
|
||||
pipe.container.scheduleRenderUpdate();
|
||||
//world.markBlockNeedsUpdate(i, j, k);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -363,7 +368,8 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
if (!APIProxy.isRemote())
|
||||
dropWire(color.reverse(), pipe.worldObj, pipe.xCoord, pipe.yCoord, pipe.zCoord);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -403,6 +409,9 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the legacyPipeRenderer
|
||||
*/
|
||||
@Override
|
||||
public void prepareTextureFor(IBlockAccess blockAccess, int i, int j, int k, Orientations connection) {
|
||||
Pipe pipe = getPipe(blockAccess, i, j, k);
|
||||
|
@ -413,18 +422,24 @@ public class BlockGenericPipe extends BlockContainer implements IBlockPipe, ITex
|
|||
|
||||
@SuppressWarnings({ "all" })
|
||||
public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l) {
|
||||
Pipe pipe = getPipe(iblockaccess, i, j, k);
|
||||
if (!isValid(pipe)) {
|
||||
CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
|
||||
return 0;
|
||||
}
|
||||
int pipeTexture = pipe.getPipeTexture();
|
||||
if (pipeTexture > 255) {
|
||||
CoreProxy.BindTexture(DefaultProps.TEXTURE_EXTERNAL);
|
||||
return pipeTexture - 256;
|
||||
}
|
||||
CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
|
||||
return pipeTexture;
|
||||
|
||||
TileEntity tile = iblockaccess.getBlockTileEntity(i, j, k);
|
||||
if (!(tile instanceof IPipeRenderState)) return 0;
|
||||
return ((IPipeRenderState)tile).getRenderState().currentTextureIndex;
|
||||
|
||||
|
||||
// Pipe pipe = getPipe(iblockaccess, i, j, k);
|
||||
// if (!isValid(pipe)) {
|
||||
// CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
|
||||
// return 0;
|
||||
// }
|
||||
// int pipeTexture = pipe.getPipeTexture();
|
||||
// if (pipeTexture > 255) {
|
||||
// CoreProxy.BindTexture(DefaultProps.TEXTURE_EXTERNAL);
|
||||
// return pipeTexture - 256;
|
||||
// }
|
||||
// CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
|
||||
// return pipeTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -295,7 +295,9 @@ public class Pipe implements IPipe, IDropControlInventory {
|
|||
|
||||
if (!foundBiggerSignal && 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()) {
|
||||
TileEntity tile = container.getTile(o);
|
||||
|
@ -352,8 +354,11 @@ public class Pipe implements IPipe, IDropControlInventory {
|
|||
signalStrength[color.ordinal()] = signal;
|
||||
internalUpdateScheduled = true;
|
||||
|
||||
if (oldSignal == 0)
|
||||
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
if (oldSignal == 0) {
|
||||
//worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
container.scheduleRenderUpdate();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
} else
|
||||
|
@ -432,9 +437,11 @@ public class Pipe implements IPipe, IDropControlInventory {
|
|||
|
||||
public void randomDisplayTick(Random random) {}
|
||||
|
||||
@Deprecated
|
||||
private DrawingState drawingState = DrawingState.DrawingPipe;
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setDrawingState(DrawingState state) {
|
||||
drawingState = state;
|
||||
}
|
||||
|
@ -537,8 +544,9 @@ public class Pipe implements IPipe, IDropControlInventory {
|
|||
activatedActions = new Action[activatedActions.length];
|
||||
broadcastSignal = new boolean[] { false, false, false, false };
|
||||
broadcastRedstone = false;
|
||||
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, BuildCraftTransport.genericPipeBlock.blockID);
|
||||
//worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
container.scheduleRenderUpdate();
|
||||
//worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, BuildCraftTransport.genericPipeBlock.blockID);
|
||||
}
|
||||
|
||||
private void resolveActions() {
|
||||
|
@ -594,13 +602,15 @@ public class Pipe implements IPipe, IDropControlInventory {
|
|||
actionsActivated(actions);
|
||||
|
||||
if (oldBroadcastRedstone != broadcastRedstone) {
|
||||
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
container.scheduleRenderUpdate();
|
||||
//worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, BuildCraftTransport.genericPipeBlock.blockID);
|
||||
}
|
||||
|
||||
for (int i = 0; i < oldBroadcastSignal.length; ++i)
|
||||
if (oldBroadcastSignal[i] != broadcastSignal[i]) {
|
||||
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
//worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||
container.scheduleRenderUpdate();
|
||||
updateSignalState();
|
||||
break;
|
||||
}
|
||||
|
@ -667,4 +677,11 @@ public class Pipe implements IPipe, IDropControlInventory {
|
|||
public boolean doDrop() {
|
||||
return logic.doDrop();
|
||||
}
|
||||
|
||||
public boolean isGateActive(){
|
||||
for (boolean b : broadcastSignal){
|
||||
if (b) return true;
|
||||
}
|
||||
return broadcastRedstone;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,89 @@
|
|||
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.TextureMatrix;
|
||||
import net.minecraft.src.buildcraft.transport.utils.WireMatrix;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ import java.util.LinkedList;
|
|||
|
||||
import net.minecraft.src.BuildCraftCore;
|
||||
import net.minecraft.src.BuildCraftTransport;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.Packet;
|
||||
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.IOverrideDefaultTriggers;
|
||||
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.IPipeEntry;
|
||||
import net.minecraft.src.buildcraft.api.IPipeTile;
|
||||
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.Orientations;
|
||||
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.TileNetworkData;
|
||||
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.DefaultProps;
|
||||
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.PacketTileUpdate;
|
||||
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,
|
||||
IPipeTile, ISynchronizedTile, IOverrideDefaultTriggers, ITileBufferHolder, IPipeConnection, IDropControlInventory, IPipeRenderState {
|
||||
|
@ -60,6 +61,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
|
||||
public Pipe pipe;
|
||||
private boolean blockNeighborChange = false;
|
||||
private boolean refreshRenderState = false;
|
||||
private boolean pipeBound = false;
|
||||
|
||||
//Store the pipe key to prevent losing pipes when a user forgets to include an addon
|
||||
|
@ -137,6 +139,12 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
computeConnections();
|
||||
pipe.onNeighborBlockChange(0);
|
||||
blockNeighborChange = false;
|
||||
refreshRenderState = true;
|
||||
}
|
||||
|
||||
if (refreshRenderState){
|
||||
refreshRenderState();
|
||||
refreshRenderState = false;
|
||||
}
|
||||
|
||||
PowerProvider provider = getPowerProvider();
|
||||
|
@ -148,6 +156,69 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
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) {
|
||||
|
||||
this.pipe = pipe;
|
||||
|
@ -173,6 +244,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
|
||||
computeConnections();
|
||||
|
||||
refreshRenderState = true;
|
||||
|
||||
if (pipe != null)
|
||||
pipe.initialize();
|
||||
|
||||
|
@ -415,7 +488,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, ILiqu
|
|||
if (oldConnections[i] != pipeConnectionsBuffer[i]) {
|
||||
Position pos = new Position(xCoord, yCoord, zCoord, Orientations.values()[i]);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public void scheduleRenderUpdate(){
|
||||
refreshRenderState = true;
|
||||
}
|
||||
|
||||
/** IPipeRenderState implementation **/
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +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 ConnectionMatrix {
|
||||
|
||||
private final boolean[] _connected = new boolean[Orientations.dirs().length];
|
||||
|
||||
public void reset(){
|
||||
for (int i = 0; i < Orientations.dirs().length; i++){
|
||||
_connected[i] = false;
|
||||
}
|
||||
}
|
||||
private boolean dirty = false;
|
||||
|
||||
public boolean isConnected(Orientations direction){
|
||||
return _connected[direction.ordinal()];
|
||||
}
|
||||
|
||||
public void setConnected(Orientations direction, boolean 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue