Moved Pipe Gate/Wire rendering to the TESR

Should greatly improve performance of wire/gate switching.
This commit is contained in:
CovertJaguar 2013-10-08 11:13:40 -07:00
parent fb0ee91183
commit 3a39b289a2
15 changed files with 556 additions and 338 deletions

View file

@ -7,7 +7,7 @@
*/ */
package buildcraft.core.render; package buildcraft.core.render;
import buildcraft.core.render.RenderEntityBlock.BlockInterface; import buildcraft.core.render.RenderEntityBlock.RenderInfo;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -31,7 +31,7 @@ public class FluidRenderer {
private static Map<Fluid, int[]> flowingRenderCache = new HashMap<Fluid, int[]>(); private static Map<Fluid, int[]> flowingRenderCache = new HashMap<Fluid, int[]>();
private static Map<Fluid, int[]> stillRenderCache = new HashMap<Fluid, int[]>(); private static Map<Fluid, int[]> stillRenderCache = new HashMap<Fluid, int[]>();
public static final int DISPLAY_STAGES = 100; public static final int DISPLAY_STAGES = 100;
private static final BlockInterface liquidBlock = new BlockInterface(); private static final RenderInfo liquidBlock = new RenderInfo();
public static Icon getFluidTexture(FluidStack fluidStack, boolean flowing) { public static Icon getFluidTexture(FluidStack fluidStack, boolean flowing) {
if (fluidStack == null) { if (fluidStack == null) {

View file

@ -8,6 +8,7 @@
package buildcraft.core.render; package buildcraft.core.render;
import buildcraft.core.EntityBlock; import buildcraft.core.EntityBlock;
import java.util.Arrays;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.Render;
@ -28,7 +29,7 @@ public class RenderEntityBlock extends Render {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
public static class BlockInterface { public static class RenderInfo {
public double minX; public double minX;
public double minY; public double minY;
@ -38,17 +39,81 @@ public class RenderEntityBlock extends Render {
public double maxZ; public double maxZ;
public Block baseBlock = Block.sand; public Block baseBlock = Block.sand;
public Icon texture = null; public Icon texture = null;
public Icon[] textureArray = null;
public boolean[] renderSide = new boolean[6];
public float light = -1f;
public int brightness = -1;
public Icon getBlockTextureFromSide(int i) { public RenderInfo() {
if (texture == null) setRenderAllSides();
return baseBlock.getBlockTextureFromSide(i); }
else
return texture; public RenderInfo(Block template, Icon[] texture) {
this();
this.baseBlock = template;
this.textureArray = texture;
}
public RenderInfo(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
this();
setBounds(minX, minY, minZ, maxX, maxY, maxZ);
} }
public float getBlockBrightness(IBlockAccess iblockaccess, int i, int j, int k) { public float getBlockBrightness(IBlockAccess iblockaccess, int i, int j, int k) {
return baseBlock.getBlockBrightness(iblockaccess, i, j, k); return baseBlock.getBlockBrightness(iblockaccess, i, j, k);
} }
public final void setBounds(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
this.minX = minX;
this.minY = minY;
this.minZ = minZ;
this.maxX = maxX;
this.maxY = maxY;
this.maxZ = maxZ;
}
public final void setRenderSingleSide(int side) {
Arrays.fill(renderSide, false);
renderSide[side] = true;
}
public final void setRenderAllSides() {
Arrays.fill(renderSide, true);
}
public void rotate() {
double temp = minX;
minX = minZ;
minZ = temp;
temp = maxX;
maxX = maxZ;
maxZ = temp;
}
public void reverseX() {
double temp = minX;
minX = 1 - maxX;
maxX = 1 - temp;
}
public void reverseZ() {
double temp = minZ;
minZ = 1 - maxZ;
maxZ = 1 - temp;
}
public Icon getBlockTextureFromSide(int i) {
if (texture != null)
return texture;
if (textureArray == null || textureArray.length == 0)
return baseBlock.getBlockTextureFromSide(i);
else {
if (i >= textureArray.length)
i = 0;
return textureArray[i];
}
}
} }
private RenderEntityBlock() { private RenderEntityBlock() {
@ -65,7 +130,7 @@ public class RenderEntityBlock extends Render {
shadowSize = entity.shadowSize; shadowSize = entity.shadowSize;
World world = entity.worldObj; World world = entity.worldObj;
BlockInterface util = new BlockInterface(); RenderInfo util = new RenderInfo();
util.texture = entity.texture; util.texture = entity.texture;
bindTexture(TextureMap.locationBlocksTexture); bindTexture(TextureMap.locationBlocksTexture);
@ -108,92 +173,169 @@ public class RenderEntityBlock extends Render {
} }
} }
public void renderBlock(BlockInterface block, IBlockAccess blockAccess, int i, int j, int k, boolean doLight, boolean doTessellating) { public void renderBlock(RenderInfo info, IBlockAccess blockAccess, int x, int y, int z, boolean doLight, boolean doTessellating) {
float f = 0.5F; renderBlock(info, blockAccess, x, y, z, x, y, z, doLight, doTessellating);
float f1 = 1.0F; }
float f2 = 0.8F;
float f3 = 0.6F;
renderBlocks.renderMaxX = block.maxX;
renderBlocks.renderMinX = block.minX;
renderBlocks.renderMaxY = block.maxY;
renderBlocks.renderMinY = block.minY;
renderBlocks.renderMaxZ = block.maxZ;
renderBlocks.renderMinZ = block.minZ;
renderBlocks.enableAO = false;
public void renderBlock(RenderInfo info, IBlockAccess blockAccess, double x, double y, double z, int lightX, int lightY, int lightZ, boolean doLight, boolean doTessellating) {
float lightBottom = 0.5F;
float lightTop = 1.0F;
float lightEastWest = 0.8F;
float lightNorthSouth = 0.6F;
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
if (doTessellating) { if (blockAccess == null)
doLight = false;
if (doTessellating && !tessellator.isDrawing)
tessellator.startDrawingQuads(); tessellator.startDrawingQuads();
}
float f4 = 0, f5 = 0;
float light = 0;
if (doLight) { if (doLight) {
f4 = block.getBlockBrightness(blockAccess, i, j, k); if (info.light < 0) {
f5 = block.getBlockBrightness(blockAccess, i, j, k); light = info.baseBlock.getBlockBrightness(blockAccess, (int) lightX, (int) lightY, (int) lightZ);
if (f5 < f4) { light = light + ((1.0f - light) * 0.4f);
f5 = f4; } else
} light = info.light;
tessellator.setColorOpaque_F(f * f5, f * f5, f * f5); int brightness = 0;
if (info.brightness < 0)
brightness = info.baseBlock.getMixedBrightnessForBlock(blockAccess, lightX, lightY, lightZ);
else
brightness = info.brightness;
tessellator.setBrightness(brightness);
tessellator.setColorOpaque_F(lightBottom * light, lightBottom * light, lightBottom * light);
} else {
tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
if (info.brightness >= 0)
tessellator.setBrightness(info.brightness);
} }
renderBlocks.renderFaceYNeg(null, 0, 0, 0, block.getBlockTextureFromSide(0)); renderBlocks.setRenderBounds(info.minX, info.minY, info.minZ, info.maxX, info.maxY, info.maxZ);
if (doLight) { if (info.renderSide[0])
f5 = block.getBlockBrightness(blockAccess, i, j, k); renderBlocks.renderFaceYNeg(info.baseBlock, x, y, z, info.getBlockTextureFromSide(0));
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f1 * f5, f1 * f5, f1 * f5);
}
renderBlocks.renderFaceYPos(null, 0, 0, 0, block.getBlockTextureFromSide(1)); if (doLight)
tessellator.setColorOpaque_F(lightTop * light, lightTop * light, lightTop * light);
if (doLight) { if (info.renderSide[1])
f5 = block.getBlockBrightness(blockAccess, i, j, k); renderBlocks.renderFaceYPos(info.baseBlock, x, y, z, info.getBlockTextureFromSide(1));
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f2 * f5, f2 * f5, f2 * f5);
}
renderBlocks.renderFaceZNeg(null, 0, 0, 0, block.getBlockTextureFromSide(2)); if (doLight)
tessellator.setColorOpaque_F(lightEastWest * light, lightEastWest * light, lightEastWest * light);
if (doLight) { if (info.renderSide[2])
f5 = block.getBlockBrightness(blockAccess, i, j, k); renderBlocks.renderFaceZNeg(info.baseBlock, x, y, z, info.getBlockTextureFromSide(2));
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f2 * f5, f2 * f5, f2 * f5);
}
renderBlocks.renderFaceZPos(null, 0, 0, 0, block.getBlockTextureFromSide(3)); if (doLight)
tessellator.setColorOpaque_F(lightEastWest * light, lightEastWest * light, lightEastWest * light);
if (doLight) { if (info.renderSide[3])
f5 = block.getBlockBrightness(blockAccess, i, j, k); renderBlocks.renderFaceZPos(info.baseBlock, x, y, z, info.getBlockTextureFromSide(3));
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f3 * f5, f3 * f5, f3 * f5);
}
renderBlocks.renderFaceXNeg(null, 0, 0, 0, block.getBlockTextureFromSide(4)); if (doLight)
tessellator.setColorOpaque_F(lightNorthSouth * light, lightNorthSouth * light, lightNorthSouth * light);
if (doLight) { if (info.renderSide[4])
f5 = block.getBlockBrightness(blockAccess, i, j, k); renderBlocks.renderFaceXNeg(info.baseBlock, x, y, z, info.getBlockTextureFromSide(4));
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f3 * f5, f3 * f5, f3 * f5);
}
renderBlocks.renderFaceXPos(null, 0, 0, 0, block.getBlockTextureFromSide(5)); if (doLight)
tessellator.setColorOpaque_F(lightNorthSouth * light, lightNorthSouth * light, lightNorthSouth * light);
if (doTessellating) { if (info.renderSide[5])
renderBlocks.renderFaceXPos(info.baseBlock, x, y, z, info.getBlockTextureFromSide(5));
if (doTessellating && tessellator.isDrawing)
tessellator.draw(); tessellator.draw();
} }
} //
// public void renderBlock(RenderInfo block, IBlockAccess blockAccess, int i, int j, int k, boolean doLight, boolean doTessellating) {
// float f = 0.5F;
// float f1 = 1.0F;
// float f2 = 0.8F;
// float f3 = 0.6F;
//
// renderBlocks.renderMaxX = block.maxX;
// renderBlocks.renderMinX = block.minX;
// renderBlocks.renderMaxY = block.maxY;
// renderBlocks.renderMinY = block.minY;
// renderBlocks.renderMaxZ = block.maxZ;
// renderBlocks.renderMinZ = block.minZ;
// renderBlocks.enableAO = false;
//
//
// Tessellator tessellator = Tessellator.instance;
//
// if (doTessellating) {
// tessellator.startDrawingQuads();
// }
//
// float f4 = 0, f5 = 0;
//
// if (doLight) {
// f4 = block.getBlockBrightness(blockAccess, i, j, k);
// f5 = block.getBlockBrightness(blockAccess, i, j, k);
// if (f5 < f4) {
// f5 = f4;
// }
// tessellator.setColorOpaque_F(f * f5, f * f5, f * f5);
// }
//
// renderBlocks.renderFaceYNeg(null, 0, 0, 0, block.getBlockTextureFromSide(0));
//
// if (doLight) {
// f5 = block.getBlockBrightness(blockAccess, i, j, k);
// if (f5 < f4) {
// f5 = f4;
// }
// tessellator.setColorOpaque_F(f1 * f5, f1 * f5, f1 * f5);
// }
//
// renderBlocks.renderFaceYPos(null, 0, 0, 0, block.getBlockTextureFromSide(1));
//
// if (doLight) {
// f5 = block.getBlockBrightness(blockAccess, i, j, k);
// if (f5 < f4) {
// f5 = f4;
// }
// tessellator.setColorOpaque_F(f2 * f5, f2 * f5, f2 * f5);
// }
//
// renderBlocks.renderFaceZNeg(null, 0, 0, 0, block.getBlockTextureFromSide(2));
//
// if (doLight) {
// f5 = block.getBlockBrightness(blockAccess, i, j, k);
// if (f5 < f4) {
// f5 = f4;
// }
// tessellator.setColorOpaque_F(f2 * f5, f2 * f5, f2 * f5);
// }
//
// renderBlocks.renderFaceZPos(null, 0, 0, 0, block.getBlockTextureFromSide(3));
//
// if (doLight) {
// f5 = block.getBlockBrightness(blockAccess, i, j, k);
// if (f5 < f4) {
// f5 = f4;
// }
// tessellator.setColorOpaque_F(f3 * f5, f3 * f5, f3 * f5);
// }
//
// renderBlocks.renderFaceXNeg(null, 0, 0, 0, block.getBlockTextureFromSide(4));
//
// if (doLight) {
// f5 = block.getBlockBrightness(blockAccess, i, j, k);
// if (f5 < f4) {
// f5 = f4;
// }
// tessellator.setColorOpaque_F(f3 * f5, f3 * f5, f3 * f5);
// }
//
// renderBlocks.renderFaceXPos(null, 0, 0, 0, block.getBlockTextureFromSide(5));
//
// if (doTessellating) {
// tessellator.draw();
// }
// }
} }

View file

@ -42,7 +42,7 @@ import buildcraft.api.transport.ISolidSideTile;
import buildcraft.core.BlockIndex; import buildcraft.core.BlockIndex;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.render.PipeWorldRenderer; import buildcraft.transport.render.PipeRendererWorld;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -167,7 +167,7 @@ public class BlockGenericPipe extends BlockContainer {
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity); super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
} }
float facadeThickness = PipeWorldRenderer.facadeThickness; float facadeThickness = PipeRendererWorld.facadeThickness;
if (tileG.hasFacade(ForgeDirection.EAST)) { if (tileG.hasFacade(ForgeDirection.EAST)) {
setBlockBounds(1 - facadeThickness, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); setBlockBounds(1 - facadeThickness, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);

View file

@ -16,14 +16,11 @@ public class PipeRenderState implements IClientState {
private boolean hasGate = false; private boolean hasGate = false;
private int gateIconIndex = 0; private int gateIconIndex = 0;
public final ConnectionMatrix pipeConnectionMatrix = new ConnectionMatrix(); public final ConnectionMatrix pipeConnectionMatrix = new ConnectionMatrix();
public final TextureMatrix textureMatrix = new TextureMatrix(); public final TextureMatrix textureMatrix = new TextureMatrix();
public final WireMatrix wireMatrix = new WireMatrix(); public final WireMatrix wireMatrix = new WireMatrix();
public final ConnectionMatrix plugMatrix = new ConnectionMatrix(); public final ConnectionMatrix plugMatrix = new ConnectionMatrix();
public final FacadeMatrix facadeMatrix = new FacadeMatrix(); public final FacadeMatrix facadeMatrix = new FacadeMatrix();
private boolean dirty = true; private boolean dirty = true;
/* /*
@ -58,14 +55,18 @@ public class PipeRenderState implements IClientState {
dirty = false; dirty = false;
pipeConnectionMatrix.clean(); pipeConnectionMatrix.clean();
textureMatrix.clean(); textureMatrix.clean();
wireMatrix.clean();
facadeMatrix.clean(); facadeMatrix.clean();
wireMatrix.clean();
} }
public boolean isDirty() { public boolean isDirty() {
return dirty || pipeConnectionMatrix.isDirty() || textureMatrix.isDirty() || wireMatrix.isDirty() || facadeMatrix.isDirty() || plugMatrix.isDirty(); return dirty || pipeConnectionMatrix.isDirty() || textureMatrix.isDirty() || wireMatrix.isDirty() || facadeMatrix.isDirty() || plugMatrix.isDirty();
} }
public boolean needsRenderUpdate() {
return pipeConnectionMatrix.isDirty() || textureMatrix.isDirty() || facadeMatrix.isDirty() || plugMatrix.isDirty();
}
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(DataOutputStream data) throws IOException {
data.writeBoolean(hasGate); data.writeBoolean(hasGate);

View file

@ -35,7 +35,6 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.transport.IPipeConnectionForced;
import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipeConnection; import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile; import buildcraft.api.transport.IPipeTile;
@ -52,6 +51,8 @@ import buildcraft.core.network.PacketTileState;
import buildcraft.transport.Gate.GateKind; import buildcraft.transport.Gate.GateKind;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.server.management.PlayerInstance;
import net.minecraft.world.WorldServer;
public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler, IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder, public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler, IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder,
IDropControlInventory, IPipeRenderState, ISyncedTile, ISolidSideTile, IGuiReturnHandler { IDropControlInventory, IPipeRenderState, ISyncedTile, ISolidSideTile, IGuiReturnHandler {
@ -80,6 +81,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
public boolean[] pipeConnectionsBuffer = new boolean[6]; public boolean[] pipeConnectionsBuffer = new boolean[6];
public SafeTimeTracker networkSyncTracker = new SafeTimeTracker(); public SafeTimeTracker networkSyncTracker = new SafeTimeTracker();
public Pipe pipe; public Pipe pipe;
private boolean sendClientUpdate = false;
private boolean blockNeighborChange = false; private boolean blockNeighborChange = false;
private boolean refreshRenderState = false; private boolean refreshRenderState = false;
private boolean pipeBound = false; private boolean pipeBound = false;
@ -186,6 +188,17 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
PowerReceiver provider = getPowerReceiver(null); PowerReceiver provider = getPowerReceiver(null);
if (provider != null) if (provider != null)
provider.update(); provider.update();
if (sendClientUpdate) {
sendClientUpdate = false;
if (worldObj instanceof WorldServer) {
WorldServer world = (WorldServer) worldObj;
PlayerInstance playerInstance = world.getPlayerManager().getOrCreateChunkWatcher(xCoord >> 4, zCoord >> 4, false);
if (playerInstance != null) {
playerInstance.sendToAllPlayersWatchingChunk(getDescriptionPacket());
}
}
}
} }
// PRECONDITION: worldObj must not be null // PRECONDITION: worldObj must not be null
@ -244,8 +257,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
} }
if (renderState.isDirty()) { if (renderState.isDirty()) {
markBlockForUpdate();
renderState.clean(); renderState.clean();
sendUpdateToClient();
} }
} }
@ -363,6 +376,10 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
return packet.getPacket(); return packet.getPacket();
} }
public void sendUpdateToClient() {
sendClientUpdate = true;
}
@Override @Override
public LinkedList<ITrigger> getTriggers() { public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> result = new LinkedList<ITrigger>(); LinkedList<ITrigger> result = new LinkedList<ITrigger>();
@ -618,9 +635,16 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
pipe.gate = new GateVanilla(pipe); pipe.gate = new GateVanilla(pipe);
pipe.gate.kind = GateKind.values()[coreState.gateKind]; pipe.gate.kind = GateKind.values()[coreState.gateKind];
} }
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
break;
case 1: {
if (renderState.needsRenderUpdate()) {
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
renderState.clean();
}
break; break;
} }
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); }
} }
@Override @Override
@ -691,10 +715,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this; return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this;
} }
public void markBlockForUpdate() {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override @Override
public void writeGuiData(DataOutputStream data) throws IOException { public void writeGuiData(DataOutputStream data) throws IOException {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler) if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler)

View file

@ -3,23 +3,23 @@ package buildcraft.transport;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.transport.render.FacadeItemRenderer; import buildcraft.transport.render.FacadeItemRenderer;
import buildcraft.transport.render.PipeItemRenderer; import buildcraft.transport.render.PipeItemRenderer;
import buildcraft.transport.render.PipeWorldRenderer; import buildcraft.transport.render.PipeRendererWorld;
import buildcraft.transport.render.PlugItemRenderer; import buildcraft.transport.render.PlugItemRenderer;
import buildcraft.transport.render.RenderPipe; import buildcraft.transport.render.PipeRendererTESR;
import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.MinecraftForgeClient;
public class TransportProxyClient extends TransportProxy { public class TransportProxyClient extends TransportProxy {
public final static PipeItemRenderer pipeItemRenderer = new PipeItemRenderer(); public final static PipeItemRenderer pipeItemRenderer = new PipeItemRenderer();
public final static PipeWorldRenderer pipeWorldRenderer = new PipeWorldRenderer(); public final static PipeRendererWorld pipeWorldRenderer = new PipeRendererWorld();
public final static FacadeItemRenderer facadeItemRenderer = new FacadeItemRenderer(); public final static FacadeItemRenderer facadeItemRenderer = new FacadeItemRenderer();
public final static PlugItemRenderer plugItemRenderer = new PlugItemRenderer(); public final static PlugItemRenderer plugItemRenderer = new PlugItemRenderer();
@Override @Override
public void registerTileEntities() { public void registerTileEntities() {
super.registerTileEntities(); super.registerTileEntities();
RenderPipe rp = new RenderPipe(); PipeRendererTESR rp = new PipeRendererTESR();
ClientRegistry.bindTileEntitySpecialRenderer(TileDummyGenericPipe.class, rp); ClientRegistry.bindTileEntitySpecialRenderer(TileDummyGenericPipe.class, rp);
ClientRegistry.bindTileEntitySpecialRenderer(TileDummyGenericPipe2.class, rp); ClientRegistry.bindTileEntitySpecialRenderer(TileDummyGenericPipe2.class, rp);
ClientRegistry.bindTileEntitySpecialRenderer(TileGenericPipe.class, rp); ClientRegistry.bindTileEntitySpecialRenderer(TileGenericPipe.class, rp);

View file

@ -72,7 +72,6 @@ public class PipeItemsDaizuli extends Pipe<PipeTransportItems> implements IPipeT
if (color != c.ordinal()) { if (color != c.ordinal()) {
this.color = c.ordinal(); this.color = c.ordinal();
container.scheduleRenderUpdate(); container.scheduleRenderUpdate();
container.markBlockForUpdate();
} }
} }

View file

@ -77,7 +77,6 @@ public class PipeItemsLapis extends Pipe<PipeTransportItems> implements IItemTra
if (color.ordinal() != container.getBlockMetadata()) { if (color.ordinal() != container.getBlockMetadata()) {
container.worldObj.setBlockMetadataWithNotify(container.xCoord, container.yCoord, container.zCoord, color.ordinal(), 3); container.worldObj.setBlockMetadataWithNotify(container.xCoord, container.yCoord, container.zCoord, color.ordinal(), 3);
container.scheduleRenderUpdate(); container.scheduleRenderUpdate();
container.markBlockForUpdate();
} }
} }

View file

@ -82,7 +82,7 @@ public abstract class PipeLogicIron {
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null; Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord)) { if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord)) {
switchPosition(); switchPosition();
pipe.container.worldObj.markBlockForUpdate(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord); pipe.container.scheduleRenderUpdate();
((IToolWrench) equipped).wrenchUsed(entityplayer, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord); ((IToolWrench) equipped).wrenchUsed(entityplayer, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
return true; return true;

View file

@ -99,7 +99,6 @@ public class PipePowerIron extends Pipe<PipeTransportPower> {
if (mode.ordinal() != container.getBlockMetadata()) { if (mode.ordinal() != container.getBlockMetadata()) {
container.worldObj.setBlockMetadataWithNotify(container.xCoord, container.yCoord, container.zCoord, mode.ordinal(), 3); container.worldObj.setBlockMetadataWithNotify(container.xCoord, container.yCoord, container.zCoord, mode.ordinal(), 3);
container.scheduleRenderUpdate(); container.scheduleRenderUpdate();
container.markBlockForUpdate();
} }
} }

View file

@ -10,13 +10,16 @@ package buildcraft.transport.render;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftCore.RenderMode; import buildcraft.BuildCraftCore.RenderMode;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipe.WireColor;
import buildcraft.core.render.FluidRenderer; import buildcraft.core.render.FluidRenderer;
import buildcraft.core.render.RenderEntityBlock; import buildcraft.core.render.RenderEntityBlock;
import buildcraft.core.render.RenderEntityBlock.BlockInterface; import buildcraft.core.render.RenderEntityBlock.RenderInfo;
import buildcraft.core.utils.EnumColor; import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeRenderState;
import buildcraft.transport.PipeTransportFluids; import buildcraft.transport.PipeTransportFluids;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.PipeTransportPower; import buildcraft.transport.PipeTransportPower;
@ -26,6 +29,7 @@ import com.google.common.collect.Maps;
import java.util.HashMap; import java.util.HashMap;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.texture.TextureMap;
@ -40,7 +44,7 @@ import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
public class RenderPipe extends TileEntitySpecialRenderer { public class PipeRendererTESR extends TileEntitySpecialRenderer {
final static private int LIQUID_STAGES = 40; final static private int LIQUID_STAGES = 40;
final static private int MAX_ITEMS_TO_RENDER = 10; final static private int MAX_ITEMS_TO_RENDER = 10;
@ -61,7 +65,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
public int[] displayPowerList = new int[POWER_STAGES]; public int[] displayPowerList = new int[POWER_STAGES];
public int[] displayPowerListOverload = new int[POWER_STAGES]; public int[] displayPowerListOverload = new int[POWER_STAGES];
public RenderPipe() { public PipeRendererTESR() {
customRenderItem = new RenderItem() { customRenderItem = new RenderItem() {
@Override @Override
public boolean shouldBob() { public boolean shouldBob() {
@ -84,7 +88,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
DisplayFluidList d = new DisplayFluidList(); DisplayFluidList d = new DisplayFluidList();
displayFluidLists.put(liquidId, d); displayFluidLists.put(liquidId, d);
BlockInterface block = new BlockInterface(); RenderInfo block = new RenderInfo();
Fluid fluid = FluidRegistry.getFluid(liquidId); Fluid fluid = FluidRegistry.getFluid(liquidId);
if (fluid.getBlockID() > 0) { if (fluid.getBlockID() > 0) {
@ -185,7 +189,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
initialized = true; initialized = true;
BlockInterface block = new BlockInterface(); RenderInfo block = new RenderInfo();
block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Power_Normal.ordinal()); block.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Power_Normal.ordinal());
float size = Utils.pipeMaxPos - Utils.pipeMinPos; float size = Utils.pipeMaxPos - Utils.pipeMinPos;
@ -250,6 +254,8 @@ public class RenderPipe extends TileEntitySpecialRenderer {
if (pipe.pipe == null) if (pipe.pipe == null)
return; return;
renderGatesWires(pipe, x, y, z);
switch (pipe.getPipeType()) { switch (pipe.getPipeType()) {
case ITEM: case ITEM:
renderSolids(pipe.pipe, x, y, z); renderSolids(pipe.pipe, x, y, z);
@ -263,6 +269,254 @@ public class RenderPipe extends TileEntitySpecialRenderer {
} }
} }
private void renderGatesWires(TileGenericPipe pipe, double x, double y, double z) {
PipeRenderState state = pipe.getRenderState();
if (state.wireMatrix.hasWire(WireColor.Red)) {
pipeWireRender(pipe, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMinPos, IPipe.WireColor.Red, x, y, z);
}
if (state.wireMatrix.hasWire(WireColor.Blue)) {
pipeWireRender(pipe, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos, IPipe.WireColor.Blue, x, y, z);
}
if (state.wireMatrix.hasWire(WireColor.Green)) {
pipeWireRender(pipe, Utils.pipeMaxPos, Utils.pipeMinPos, Utils.pipeMinPos, IPipe.WireColor.Green, x, y, z);
}
if (state.wireMatrix.hasWire(WireColor.Yellow)) {
pipeWireRender(pipe, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, IPipe.WireColor.Yellow, x, y, z);
}
if (state.hasGate()) {
pipeGateRender(pipe, x, y, z);
}
}
private void pipeWireRender(TileGenericPipe pipe, float cx, float cy, float cz, IPipe.WireColor color, double x, double y, double z) {
PipeRenderState state = pipe.getRenderState();
float minX = Utils.pipeMinPos;
float minY = Utils.pipeMinPos;
float minZ = Utils.pipeMinPos;
float maxX = Utils.pipeMaxPos;
float maxY = Utils.pipeMaxPos;
float maxZ = Utils.pipeMaxPos;
boolean foundX = false, foundY = false, foundZ = false;
if (state.wireMatrix.isWireConnected(color, ForgeDirection.WEST)) {
minX = 0;
foundX = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.EAST)) {
maxX = 1;
foundX = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.DOWN)) {
minY = 0;
foundY = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.UP)) {
maxY = 1;
foundY = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.NORTH)) {
minZ = 0;
foundZ = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.SOUTH)) {
maxZ = 1;
foundZ = true;
}
boolean center = false;
if (minX == 0 && maxX != 1 && (foundY || foundZ))
if (cx == Utils.pipeMinPos) {
maxX = Utils.pipeMinPos;
} else {
center = true;
}
if (minX != 0 && maxX == 1 && (foundY || foundZ))
if (cx == Utils.pipeMaxPos) {
minX = Utils.pipeMaxPos;
} else {
center = true;
}
if (minY == 0 && maxY != 1 && (foundX || foundZ))
if (cy == Utils.pipeMinPos) {
maxY = Utils.pipeMinPos;
} else {
center = true;
}
if (minY != 0 && maxY == 1 && (foundX || foundZ))
if (cy == Utils.pipeMaxPos) {
minY = Utils.pipeMaxPos;
} else {
center = true;
}
if (minZ == 0 && maxZ != 1 && (foundX || foundY))
if (cz == Utils.pipeMinPos) {
maxZ = Utils.pipeMinPos;
} else {
center = true;
}
if (minZ != 0 && maxZ == 1 && (foundX || foundY))
if (cz == Utils.pipeMaxPos) {
minZ = Utils.pipeMaxPos;
} else {
center = true;
}
boolean found = foundX || foundY || foundZ;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_CULL_FACE);
RenderHelper.disableStandardItemLighting();
GL11.glColor3f(1, 1, 1);
GL11.glTranslatef((float) x, (float) y, (float) z);
bindTexture(TextureMap.locationBlocksTexture);
RenderInfo box = new RenderInfo();
box.texture = BuildCraftTransport.instance.wireIconProvider.getIcon(state.wireMatrix.getWireIconIndex(color));
// Z render
if (minZ != Utils.pipeMinPos || maxZ != Utils.pipeMaxPos || !found) {
box.setBounds(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);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
// X render
if (minX != Utils.pipeMinPos || maxX != Utils.pipeMaxPos || !found) {
box.setBounds(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);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
// Y render
if (minY != Utils.pipeMinPos || maxY != Utils.pipeMaxPos || !found) {
box.setBounds(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);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (center || !found) {
box.setBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, cy == Utils.pipeMinPos ? cy - 0.05F : cy, 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);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
RenderHelper.enableStandardItemLighting();
GL11.glPopAttrib();
GL11.glPopMatrix();
}
private void pipeGateRender(TileGenericPipe pipe, double x, double y, double z) {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
// GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_CULL_FACE);
// GL11.glDisable(GL11.GL_TEXTURE_2D);
RenderHelper.disableStandardItemLighting();
GL11.glColor3f(1, 1, 1);
GL11.glTranslatef((float) x, (float) y, (float) z);
bindTexture(TextureMap.locationBlocksTexture);
PipeRenderState state = pipe.getRenderState();
float min = Utils.pipeMinPos + 0.05F;
float max = Utils.pipeMaxPos - 0.05F;
RenderInfo box = new RenderInfo();
box.texture = BuildCraftTransport.instance.gateIconProvider.getIcon(state.getGateIconIndex());
if (shouldRenderNormalPipeSide(state, ForgeDirection.WEST)) {
box.setBounds(Utils.pipeMinPos - 0.10F, min, min, Utils.pipeMinPos + 0.001F, max, max);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.EAST)) {
box.setBounds(Utils.pipeMaxPos + 0.001F, min, min, Utils.pipeMaxPos + 0.10F, max, max);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.DOWN)) {
box.setBounds(min, Utils.pipeMinPos - 0.10F, min, max, Utils.pipeMinPos + 0.001F, max);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.UP)) {
box.setBounds(min, Utils.pipeMaxPos + 0.001F, min, max, Utils.pipeMaxPos + 0.10F, max);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.NORTH)) {
box.setBounds(min, min, Utils.pipeMinPos - 0.10F, max, max, Utils.pipeMinPos + 0.001F);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.SOUTH)) {
box.setBounds(min, min, Utils.pipeMaxPos + 0.001F, max, max, Utils.pipeMaxPos + 0.10F);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
RenderHelper.enableStandardItemLighting();
GL11.glPopAttrib();
GL11.glPopMatrix();
}
private boolean shouldRenderNormalPipeSide(PipeRenderState state, ForgeDirection direction) {
return !state.pipeConnectionMatrix.isConnected(direction) && state.facadeMatrix.getFacadeBlockId(direction) == 0 && !state.plugMatrix.isConnected(direction) && !isOpenOrientation(state, direction);
}
public boolean isOpenOrientation(PipeRenderState state, ForgeDirection direction) {
int connections = 0;
ForgeDirection targetOrientation = ForgeDirection.UNKNOWN;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (state.pipeConnectionMatrix.isConnected(o)) {
connections++;
if (connections == 1)
targetOrientation = o;
}
}
if (connections > 1 || connections == 0)
return false;
return targetOrientation.getOpposite() == direction;
}
private void renderPower(Pipe<PipeTransportPower> pipe, double x, double y, double z) { private void renderPower(Pipe<PipeTransportPower> pipe, double x, double y, double z) {
initializeDisplayPowerList(pipe.container.worldObj); initializeDisplayPowerList(pipe.container.worldObj);
@ -449,7 +703,7 @@ public class RenderPipe extends TileEntitySpecialRenderer {
customRenderItem.doRenderItem(dummyEntityItem, 0, 0, 0, 0, 0); customRenderItem.doRenderItem(dummyEntityItem, 0, 0, 0, 0, 0);
if (color != null) { if (color != null) {
bindTexture(TextureMap.locationBlocksTexture); bindTexture(TextureMap.locationBlocksTexture);
BlockInterface block = new BlockInterface(); RenderInfo block = new RenderInfo();
block.texture = PipeIconProvider.TYPE.ItemBox.getIcon(); block.texture = PipeIconProvider.TYPE.ItemBox.getIcon();

View file

@ -2,8 +2,6 @@ package buildcraft.transport.render;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipe.WireColor;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.IPipeRenderState; import buildcraft.transport.IPipeRenderState;
@ -20,7 +18,7 @@ import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
public class PipeWorldRenderer implements ISimpleBlockRenderingHandler { public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
public static final float facadeThickness = 1F / 16F; public static final float facadeThickness = 1F / 16F;
@ -197,31 +195,6 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
renderblocks.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); renderblocks.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
if (state.wireMatrix.hasWire(WireColor.Red)) {
state.currentTexture = BuildCraftTransport.instance.wireIconProvider.getIcon(state.wireMatrix.getWireIconIndex(WireColor.Red));
pipeWireRender(renderblocks, block, state, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMinPos, IPipe.WireColor.Red, x, y, z);
}
if (state.wireMatrix.hasWire(WireColor.Blue)) {
state.currentTexture = BuildCraftTransport.instance.wireIconProvider.getIcon(state.wireMatrix.getWireIconIndex(WireColor.Blue));
pipeWireRender(renderblocks, block, state, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos, IPipe.WireColor.Blue, x, y, z);
}
if (state.wireMatrix.hasWire(WireColor.Green)) {
state.currentTexture = BuildCraftTransport.instance.wireIconProvider.getIcon(state.wireMatrix.getWireIconIndex(WireColor.Green));
pipeWireRender(renderblocks, block, state, Utils.pipeMaxPos, Utils.pipeMinPos, Utils.pipeMinPos, IPipe.WireColor.Green, x, y, z);
}
if (state.wireMatrix.hasWire(WireColor.Yellow)) {
state.currentTexture = BuildCraftTransport.instance.wireIconProvider.getIcon(state.wireMatrix.getWireIconIndex(WireColor.Yellow));
pipeWireRender(renderblocks, block, state, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, IPipe.WireColor.Yellow, x, y, z);
}
if (state.hasGate()) {
pipeGateRender(renderblocks, block, state, x, y, z);
}
pipeFacadeRenderer(renderblocks, block, state, x, y, z); pipeFacadeRenderer(renderblocks, block, state, x, y, z);
pipePlugRenderer(renderblocks, block, state, x, y, z); pipePlugRenderer(renderblocks, block, state, x, y, z);
@ -392,190 +365,6 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
} }
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;
float minZ = Utils.pipeMinPos;
float maxX = Utils.pipeMaxPos;
float maxY = Utils.pipeMaxPos;
float maxZ = Utils.pipeMaxPos;
boolean foundX = false, foundY = false, foundZ = false;
if (state.wireMatrix.isWireConnected(color, ForgeDirection.WEST)) {
minX = 0;
foundX = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.EAST)) {
maxX = 1;
foundX = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.DOWN)) {
minY = 0;
foundY = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.UP)) {
maxY = 1;
foundY = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.NORTH)) {
minZ = 0;
foundZ = true;
}
if (state.wireMatrix.isWireConnected(color, ForgeDirection.SOUTH)) {
maxZ = 1;
foundZ = true;
}
boolean center = false;
if (minX == 0 && maxX != 1 && (foundY || foundZ))
if (cx == Utils.pipeMinPos) {
maxX = Utils.pipeMinPos;
} else {
center = true;
}
if (minX != 0 && maxX == 1 && (foundY || foundZ))
if (cx == Utils.pipeMaxPos) {
minX = Utils.pipeMaxPos;
} else {
center = true;
}
if (minY == 0 && maxY != 1 && (foundX || foundZ))
if (cy == Utils.pipeMinPos) {
maxY = Utils.pipeMinPos;
} else {
center = true;
}
if (minY != 0 && maxY == 1 && (foundX || foundZ))
if (cy == Utils.pipeMaxPos) {
minY = Utils.pipeMaxPos;
} else {
center = true;
}
if (minZ == 0 && maxZ != 1 && (foundX || foundY))
if (cz == Utils.pipeMinPos) {
maxZ = Utils.pipeMinPos;
} else {
center = true;
}
if (minZ != 0 && maxZ == 1 && (foundX || foundY))
if (cz == Utils.pipeMaxPos) {
minZ = Utils.pipeMaxPos;
} else {
center = true;
}
boolean found = foundX || foundY || foundZ;
// Z render
if (minZ != Utils.pipeMinPos || maxZ != Utils.pipeMaxPos || !found) {
renderblocks.setRenderBounds(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, x, y, z);
}
// X render
if (minX != Utils.pipeMinPos || maxX != Utils.pipeMaxPos || !found) {
renderblocks.setRenderBounds(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, x, y, z);
}
// Y render
if (minY != Utils.pipeMinPos || maxY != Utils.pipeMaxPos || !found) {
renderblocks.setRenderBounds(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, x, y, z);
}
if (center || !found) {
renderblocks.setRenderBounds(cx == Utils.pipeMinPos ? cx - 0.05F : cx, cy == Utils.pipeMinPos ? cy - 0.05F : cy, 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, x, y, z);
}
}
private void pipeGateRender(RenderBlocks renderblocks, Block block, PipeRenderState state, int x, int y, int z) {
state.currentTexture = BuildCraftTransport.instance.gateIconProvider.getIcon(state.getGateIconIndex());
float min = Utils.pipeMinPos + 0.05F;
float max = Utils.pipeMaxPos - 0.05F;
if (shouldRenderNormalPipeSide(state, ForgeDirection.WEST)) {
renderblocks.setRenderBounds(Utils.pipeMinPos - 0.10F, min, min, Utils.pipeMinPos + 0.001F, max, max);
renderblocks.renderStandardBlock(block, x, y, z);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.EAST)) {
renderblocks.setRenderBounds(Utils.pipeMaxPos + 0.001F, min, min, Utils.pipeMaxPos + 0.10F, max, max);
renderblocks.renderStandardBlock(block, x, y, z);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.DOWN)) {
renderblocks.setRenderBounds(min, Utils.pipeMinPos - 0.10F, min, max, Utils.pipeMinPos + 0.001F, max);
renderblocks.renderStandardBlock(block, x, y, z);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.UP)) {
renderblocks.setRenderBounds(min, Utils.pipeMaxPos + 0.001F, min, max, Utils.pipeMaxPos + 0.10F, max);
renderblocks.renderStandardBlock(block, x, y, z);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.NORTH)) {
renderblocks.setRenderBounds(min, min, Utils.pipeMinPos - 0.10F, max, max, Utils.pipeMinPos + 0.001F);
renderblocks.renderStandardBlock(block, x, y, z);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.SOUTH)) {
renderblocks.setRenderBounds(min, min, Utils.pipeMaxPos + 0.001F, max, max, Utils.pipeMaxPos + 0.10F);
renderblocks.renderStandardBlock(block, x, y, z);
}
}
private boolean shouldRenderNormalPipeSide(PipeRenderState state, ForgeDirection direction) {
return !state.pipeConnectionMatrix.isConnected(direction) && state.facadeMatrix.getFacadeBlockId(direction) == 0 && !state.plugMatrix.isConnected(direction) && !isOpenOrientation(state, direction);
}
public boolean isOpenOrientation(PipeRenderState state, ForgeDirection direction) {
int connections = 0;
ForgeDirection targetOrientation = ForgeDirection.UNKNOWN;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (state.pipeConnectionMatrix.isConnected(o)) {
connections++;
if (connections == 1)
targetOrientation = o;
}
}
if (connections > 1 || connections == 0)
return false;
return targetOrientation.getOpposite() == direction;
}
@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

View file

@ -8,9 +8,8 @@ import net.minecraftforge.common.ForgeDirection;
public class ConnectionMatrix { public class ConnectionMatrix {
private final BitSet _connected = new BitSet(ForgeDirection.VALID_DIRECTIONS.length); private BitSet _connected = new BitSet(ForgeDirection.VALID_DIRECTIONS.length);
private final BitSetCodec _bitSetCodec = new BitSetCodec(); private final BitSetCodec _bitSetCodec = new BitSetCodec();
private boolean dirty = false; private boolean dirty = false;
public boolean isConnected(ForgeDirection direction) { public boolean isConnected(ForgeDirection direction) {
@ -37,6 +36,11 @@ public class ConnectionMatrix {
} }
public void readData(DataInputStream data) throws IOException { public void readData(DataInputStream data) throws IOException {
_bitSetCodec.decode(data.readByte(), _connected); BitSet connection = new BitSet(ForgeDirection.VALID_DIRECTIONS.length);
_bitSetCodec.decode(data.readByte(), connection);
if (!_connected.equals(connection)) {
_connected = connection;
dirty = true;
}
} }
} }

View file

@ -6,9 +6,9 @@ import java.io.IOException;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
public class FacadeMatrix { public class FacadeMatrix {
private final int[] _blockIds = new int[ForgeDirection.VALID_DIRECTIONS.length]; private final int[] _blockIds = new int[ForgeDirection.VALID_DIRECTIONS.length];
private final int[] _blockMetas = new int[ForgeDirection.VALID_DIRECTIONS.length]; private final int[] _blockMetas = new int[ForgeDirection.VALID_DIRECTIONS.length];
private boolean dirty = false; private boolean dirty = false;
public FacadeMatrix() { public FacadeMatrix() {
@ -38,17 +38,25 @@ public class FacadeMatrix {
dirty = false; dirty = false;
} }
public void readData(DataInputStream data) throws IOException {
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
_blockIds[i] = data.readShort();
_blockMetas[i] = data.readByte();
}
}
public void writeData(DataOutputStream data) throws IOException { public void writeData(DataOutputStream data) throws IOException {
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
data.writeShort(_blockIds[i]); data.writeShort(_blockIds[i]);
data.writeByte(_blockMetas[i]); data.writeByte(_blockMetas[i]);
} }
} }
public void readData(DataInputStream data) throws IOException {
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
short id = data.readShort();
if (_blockIds[i] != id) {
_blockIds[i] = id;
dirty = true;
}
byte meta = data.readByte();
if (_blockMetas[i] != meta) {
_blockMetas[i] = meta;
dirty = true;
}
}
}
} }

View file

@ -8,7 +8,6 @@ import net.minecraftforge.common.ForgeDirection;
public class TextureMatrix { public class TextureMatrix {
private final int[] _iconIndexes = new int[7]; private final int[] _iconIndexes = new int[7];
private boolean dirty = false; private boolean dirty = false;
public int getTextureIndex(ForgeDirection direction) { public int getTextureIndex(ForgeDirection direction) {
@ -38,7 +37,11 @@ public class TextureMatrix {
public void readData(DataInputStream data) throws IOException { public void readData(DataInputStream data) throws IOException {
for (int i = 0; i < _iconIndexes.length; i++) { for (int i = 0; i < _iconIndexes.length; i++) {
_iconIndexes[i] = data.readByte(); int icon = data.readByte();
if (_iconIndexes[i] != icon) {
_iconIndexes[i] = icon;
dirty = true;
}
} }
} }
} }