Redesigned texture states system

This commit is contained in:
Semion Nadezhdin 2014-07-12 04:02:55 +04:00
parent 5ab655a226
commit 725644b5fc
10 changed files with 267 additions and 95 deletions

View file

@ -0,0 +1,29 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*
* Facade API extraction performed by Itaros(Semion Nadezhdin)
*/
package buildcraft.api.rendering;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
/*
* Implement on Block class to make it able to respond to facade render helper queries
* For implementation details look into BlockGenericPipe implementation
*/
public interface ICullable {
//Side Rendering States
//They are used to effectively cull obstructed sides while processing facades.
//Make sure your implementation is correct otherwise expect FPS drop
void setRenderSide(ForgeDirection side, boolean render);
void setRenderAllSides();
boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side);
}

View file

@ -0,0 +1,12 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|rendering")
package buildcraft.api.rendering;
import cpw.mods.fml.common.API;

View file

@ -16,6 +16,10 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -36,13 +40,7 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog; import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex; import buildcraft.api.core.BlockIndex;
@ -63,10 +61,13 @@ import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.GateDefinition; import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory; import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.gates.ItemGate; import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.render.ITextureStates;
import buildcraft.transport.render.PipeRendererWorld; import buildcraft.transport.render.PipeRendererWorld;
import buildcraft.transport.render.TextureStateManager;
import buildcraft.transport.utils.FacadeMatrix; import buildcraft.transport.utils.FacadeMatrix;
public class BlockGenericPipe extends BlockBuildCraft {
public class BlockGenericPipe extends BlockBuildCraft implements ITextureStates{
public static int facadeRenderColor = -1; public static int facadeRenderColor = -1;
public static Map<Item, Class<? extends Pipe>> pipes = new HashMap<Item, Class<? extends Pipe>>(); public static Map<Item, Class<? extends Pipe>> pipes = new HashMap<Item, Class<? extends Pipe>>();
@ -74,6 +75,8 @@ public class BlockGenericPipe extends BlockBuildCraft {
private static long lastRemovedDate = -1; private static long lastRemovedDate = -1;
private static final ForgeDirection[] DIR_VALUES = ForgeDirection.values();
static enum Part { static enum Part {
Pipe, Pipe,
Gate, Gate,
@ -82,6 +85,9 @@ public class BlockGenericPipe extends BlockBuildCraft {
RobotStation RobotStation
} }
@SideOnly(Side.CLIENT)
private TextureStateManager textureState;
static class RaytraceResult { static class RaytraceResult {
public final Part hitPart; public final Part hitPart;
public final MovingObjectPosition movingObjectPosition; public final MovingObjectPosition movingObjectPosition;
@ -100,7 +106,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
return String.format("RayTraceResult: %s, %s", hitPart == null ? "null" : hitPart.name(), boundingBox == null ? "null" : boundingBox.toString()); return String.format("RayTraceResult: %s, %s", hitPart == null ? "null" : hitPart.name(), boundingBox == null ? "null" : boundingBox.toString());
} }
} }
private static final ForgeDirection[] DIR_VALUES = ForgeDirection.values();
private boolean skippedFirstIconRegister; private boolean skippedFirstIconRegister;
private int renderMask = 0; private int renderMask = 0;
@ -1028,20 +1034,17 @@ public class BlockGenericPipe extends BlockBuildCraft {
pipe.dropItem(pipeWire.getStack()); pipe.dropItem(pipeWire.getStack());
} }
@SuppressWarnings({"all"}) @SideOnly(Side.CLIENT)
public TextureStateManager getTextureState() {
return textureState;
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@Override @Override
public IIcon getIcon(IBlockAccess iblockaccess, int x, int y, int z, int side) { public IIcon getIcon(int side, int meta) {
TileEntity tile = iblockaccess.getTileEntity(x, y, z); return textureState.isSided() ? textureState.getTextureArray()[side] : textureState.getTexture();
if (!(tile instanceof TileGenericPipe)) {
return null;
}
if (((TileGenericPipe) tile).renderState.textureArray != null) {
return ((TileGenericPipe) tile).renderState.textureArray[side];
}
return ((TileGenericPipe) tile).renderState.currentTexture;
} }
@Override @Override
public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity) { public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity) {
super.onEntityCollidedWithBlock(world, i, j, k, entity); super.onEntityCollidedWithBlock(world, i, j, k, entity);
@ -1185,6 +1188,8 @@ public class BlockGenericPipe extends BlockBuildCraft {
return; return;
} }
textureState = new TextureStateManager(null);
BuildCraftTransport.instance.wireIconProvider.registerIcons(iconRegister); BuildCraftTransport.instance.wireIconProvider.registerIcons(iconRegister);
for (Item i : pipes.keySet()) { for (Item i : pipes.keySet()) {
@ -1207,12 +1212,6 @@ public class BlockGenericPipe extends BlockBuildCraft {
} }
} }
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int par1, int par2) {
return BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.Stripes.ordinal());
}
/** /**
* Spawn a digging particle effect in the world, this is a wrapper around * Spawn a digging particle effect in the world, this is a wrapper around
* EffectRenderer.addBlockHitEffects to allow the block more control over * EffectRenderer.addBlockHitEffects to allow the block more control over
@ -1337,4 +1336,11 @@ public class BlockGenericPipe extends BlockBuildCraft {
} }
} }
} }
@Override
public Block getBlock() {
return this;
}
} }

View file

@ -9,12 +9,6 @@
package buildcraft.transport; package buildcraft.transport;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.core.network.IClientState; import buildcraft.core.network.IClientState;
import buildcraft.transport.utils.ConnectionMatrix; import buildcraft.transport.utils.ConnectionMatrix;
import buildcraft.transport.utils.FacadeMatrix; import buildcraft.transport.utils.FacadeMatrix;
@ -33,13 +27,6 @@ public class PipeRenderState implements IClientState {
public final FacadeMatrix facadeMatrix = new FacadeMatrix(); public final FacadeMatrix facadeMatrix = new FacadeMatrix();
public final GateMatrix gateMatrix = new GateMatrix(); public final GateMatrix gateMatrix = new GateMatrix();
/*
* This is a placeholder for the pipe renderer to set to a value that the BlockGenericPipe->TileGenericPipe will then return the the WorldRenderer
*/
@SideOnly(Side.CLIENT)
public IIcon currentTexture;
@SideOnly(Side.CLIENT)
public IIcon[] textureArray;
private boolean dirty = true; private boolean dirty = true;

View file

@ -11,6 +11,9 @@ package buildcraft.transport;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.logging.Level; import java.util.logging.Level;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -23,17 +26,12 @@ import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog; import buildcraft.api.core.BCLog;
@ -67,6 +65,7 @@ import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.gates.ItemGate; import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.utils.RobotStationState; import buildcraft.transport.utils.RobotStationState;
public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler, public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler,
IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder, IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder,
IDropControlInventory, ISyncedTile, ISolidSideTile, IGuiReturnHandler{ IDropControlInventory, ISyncedTile, ISolidSideTile, IGuiReturnHandler{
@ -1113,4 +1112,5 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
((IPowerReceptor) pipe).doWork(workProvider); ((IPowerReceptor) pipe).doWork(workProvider);
} }
} }
} }

View file

@ -13,9 +13,7 @@ import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.core.CoreConstants; import buildcraft.core.CoreConstants;
import buildcraft.core.utils.MatrixTranformations; import buildcraft.core.utils.MatrixTranformations;
@ -93,8 +91,11 @@ public final class FacadeRenderHelper {
rotated[2][1] - zOffsets[side.ordinal()]); rotated[2][1] - zOffsets[side.ordinal()]);
} }
public static void pipeFacadeRenderer(RenderBlocks renderblocks, BlockGenericPipe block, PipeRenderState state, int x, int y, int z) { public static void pipeFacadeRenderer(RenderBlocks renderblocks, ITextureStates blockStateMachine, PipeRenderState state, int x, int y, int z) {
state.textureArray = new IIcon[6]; ITextureStates textureManager = (ITextureStates) blockStateMachine;
IIcon[] textures = textureManager.getTextureState().popArray();
//block_statemachine.setRenderAllSides();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
Block renderBlock = state.facadeMatrix.getFacadeBlock(direction); Block renderBlock = state.facadeMatrix.getFacadeBlock(direction);
@ -105,11 +106,11 @@ public final class FacadeRenderHelper {
int renderMeta = state.facadeMatrix.getFacadeMetaId(direction); int renderMeta = state.facadeMatrix.getFacadeMetaId(direction);
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
state.textureArray[side.ordinal()] = renderBlock.getIcon(side.ordinal(), renderMeta); textures[side.ordinal()] = renderBlock.getIcon(side.ordinal(), renderMeta);
if (side == direction || side == direction.getOpposite()) { if (side == direction || side == direction.getOpposite()) {
block.setRenderSide(side, true); blockStateMachine.setRenderSide(side, true);
} else { } else {
block.setRenderSide(side, state.facadeMatrix.getFacadeBlock(side) == null); blockStateMachine.setRenderSide(side, state.facadeMatrix.getFacadeBlock(side) == null);
} }
} }
@ -139,7 +140,7 @@ public final class FacadeRenderHelper {
rotated[2][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2; rotated[2][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2;
MatrixTranformations.transform(rotated, direction); MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction); setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade); rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4; rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4;
@ -147,26 +148,26 @@ public final class FacadeRenderHelper {
rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2; rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2;
MatrixTranformations.transform(rotated, direction); MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction); setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade); rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = 0.0F; rotated[0][0] = 0.0F;
rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2; rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2;
MatrixTranformations.transform(rotated, direction); MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction); setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade); rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2; rotated[0][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2;
rotated[0][1] = 1F; rotated[0][1] = 1F;
MatrixTranformations.transform(rotated, direction); MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction); setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
} else { // Solid facade } else { // Solid facade
float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade); float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade);
MatrixTranformations.transform(rotated, direction); MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction); setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
} }
if (renderBlock.getRenderType() == 31) { if (renderBlock.getRenderType() == 31) {
@ -183,10 +184,10 @@ public final class FacadeRenderHelper {
BlockGenericPipe.facadeRenderColor = -1; BlockGenericPipe.facadeRenderColor = -1;
} }
state.textureArray = null; textureManager.getTextureState().pushArray();
block.setRenderAllSides(); blockStateMachine.setRenderAllSides();
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe textureManager.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal())); // Structure Pipe
// Always render connectors in pass 0 // Always render connectors in pass 0
if (PipeRendererWorld.renderPass == 0) { if (PipeRendererWorld.renderPass == 0) {
@ -196,7 +197,7 @@ public final class FacadeRenderHelper {
MatrixTranformations.transform(rotated, direction); MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
} }
} }
} }

View file

@ -0,0 +1,60 @@
package buildcraft.transport.render;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
/*
* This is fake block to render pluggables without altering host state
* May prove useful if we will make API for roboports, plugs and facades
*/
@SideOnly(Side.CLIENT)
public class FakePluggablesStateBlock extends Block implements ITextureStates {
private int renderMask = 0;
private TextureStateManager textureState;
protected FakePluggablesStateBlock() {
super(Material.glass);
textureState = new TextureStateManager(null); //Always Clientside
}
public TextureStateManager getTextureState() {
return textureState;
}
@Override
public IIcon getIcon(int side, int meta) {
return textureState.isSided() ? textureState.getTextureArray()[side] : textureState.getTexture();
}
@Override
public void setRenderSide(ForgeDirection side, boolean render) {
if (render) {
renderMask |= 1 << side.ordinal();
} else {
renderMask &= ~(1 << side.ordinal());
}
}
@Override
public void setRenderAllSides() {
renderMask = 0x3f;
}
@Override
public Block getBlock() {
return this;
}
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side) {
return (renderMask & (1 << side)) != 0;
}
}

View file

@ -0,0 +1,14 @@
package buildcraft.transport.render;
import net.minecraft.block.Block;
import net.minecraft.util.IIcon;
import buildcraft.api.rendering.ICullable;
public interface ITextureStates extends ICullable {
TextureStateManager getTextureState();
IIcon getIcon(int side, int meta);
Block getBlock();
}

View file

@ -8,16 +8,16 @@
*/ */
package buildcraft.transport.render; package buildcraft.transport.render;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.core.CoreConstants; import buildcraft.core.CoreConstants;
@ -28,10 +28,13 @@ import buildcraft.transport.PipeRenderState;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.TransportProxy; import buildcraft.transport.TransportProxy;
public class PipeRendererWorld implements ISimpleBlockRenderingHandler { public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
public static int renderPass = -1; public static int renderPass = -1;
public FakePluggablesStateBlock fakeBlock = new FakePluggablesStateBlock();
public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, BlockGenericPipe block, TileGenericPipe tile, int x, int y, int z) { public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, BlockGenericPipe block, TileGenericPipe tile, int x, int y, int z) {
PipeRenderState state = tile.renderState; PipeRenderState state = tile.renderState;
IIconProvider icons = tile.getPipeIcons(); IIconProvider icons = tile.getPipeIcons();
@ -40,6 +43,8 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
return; return;
} }
// Force pipe render into pass 0 // Force pipe render into pass 0
if (renderPass == 0) { if (renderPass == 0) {
int connectivity = state.pipeConnectionMatrix.getMask(); int connectivity = state.pipeConnectionMatrix.getMask();
@ -50,7 +55,7 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
if (connectivity != 0x3f) { // note: 0x3f = 0x111111 = all sides if (connectivity != 0x3f) { // note: 0x3f = 0x111111 = all sides
resetToCenterDimensions(dim); resetToCenterDimensions(dim);
state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN)); block.getTextureState().set(icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.UNKNOWN)));
renderTwoWayBlock(renderblocks, block, x, y, z, dim, connectivity ^ 0x3f); renderTwoWayBlock(renderblocks, block, x, y, z, dim, connectivity ^ 0x3f);
} }
@ -74,7 +79,7 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
int renderMask = (3 << (dir / 2 * 2)) ^ 0x3f; int renderMask = (3 << (dir / 2 * 2)) ^ 0x3f;
// render sub block // render sub block
state.currentTexture = icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.VALID_DIRECTIONS[dir])); block.getTextureState().set(icons.getIcon(state.textureMatrix.getTextureIndex(ForgeDirection.VALID_DIRECTIONS[dir])));
renderTwoWayBlock(renderblocks, block, x, y, z, dim, renderMask); renderTwoWayBlock(renderblocks, block, x, y, z, dim, renderMask);
} }
@ -83,12 +88,13 @@ public class PipeRendererWorld 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);
// Facade renderer handles rendering in both passes // Facade renderer handles rendering in both passes
pipeFacadeRenderer(renderblocks, block, state, x, y, z); pipeFacadeRenderer(renderblocks, fakeBlock, state, x, y, z);
//block.setRenderAllSides();//Start fresh
// Force other opaque renders into pass 0 // Force other opaque renders into pass 0
if (renderPass == 0) { if (renderPass == 0) {
pipePlugRenderer(renderblocks, block, state, x, y, z); pipePlugRenderer(renderblocks, fakeBlock, state, x, y, z);
pipeRobotStationRenderer(renderblocks, block, state, x, y, z); pipeRobotStationRenderer(renderblocks, fakeBlock, state, x, y, z);
} }
} }
@ -117,11 +123,11 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(block, x, y, z);
} }
private void pipeFacadeRenderer(RenderBlocks renderblocks, BlockGenericPipe block, PipeRenderState state, int x, int y, int z) { private void pipeFacadeRenderer(RenderBlocks renderblocks, ITextureStates blockStateMachine, PipeRenderState state, int x, int y, int z) {
FacadeRenderHelper.pipeFacadeRenderer(renderblocks, block, state, x, y, z); FacadeRenderHelper.pipeFacadeRenderer(renderblocks, blockStateMachine, state, x, y, z);
} }
private void pipePlugRenderer(RenderBlocks renderblocks, Block block, PipeRenderState state, int x, int y, int z) { private void pipePlugRenderer(RenderBlocks renderblocks, ITextureStates blockStateMachine, PipeRenderState state, int x, int y, int z) {
float zFightOffset = 1F / 4096F; float zFightOffset = 1F / 4096F;
float[][] zeroState = new float[3][2]; float[][] zeroState = new float[3][2];
@ -135,7 +141,7 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
zeroState[2][0] = 0.25F + zFightOffset; zeroState[2][0] = 0.25F + zFightOffset;
zeroState[2][1] = 0.75F - zFightOffset; zeroState[2][1] = 0.75F - zFightOffset;
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal())); // Structure Pipe
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (state.plugMatrix.isConnected(direction)) { if (state.plugMatrix.isConnected(direction)) {
@ -143,7 +149,7 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
MatrixTranformations.transform(rotated, direction); MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
} }
} }
@ -157,7 +163,7 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
zeroState[2][0] = 0.25F + 0.125F / 2; zeroState[2][0] = 0.25F + 0.125F / 2;
zeroState[2][1] = 0.75F - 0.125F / 2; zeroState[2][1] = 0.75F - 0.125F / 2;
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure Pipe blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal())); // Structure Pipe
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (state.plugMatrix.isConnected(direction)) { if (state.plugMatrix.isConnected(direction)) {
@ -165,14 +171,14 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
MatrixTranformations.transform(rotated, direction); MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]); renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
} }
} }
} }
private void pipeRobotStationPartRender(RenderBlocks renderblocks, private void pipeRobotStationPartRender(RenderBlocks renderblocks,
Block block, PipeRenderState state, int x, int y, int z, ITextureStates blockStateMachine, PipeRenderState state, int x, int y, int z,
float xStart, float xEnd, float yStart, float yEnd, float zStart, float xStart, float xEnd, float yStart, float yEnd, float zStart,
float zEnd) { float zEnd) {
@ -194,16 +200,16 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
switch (state.robotStationMatrix.getState(direction)) { switch (state.robotStationMatrix.getState(direction)) {
case None: case None:
case Available: case Available:
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStation.ordinal()); .getIcon(PipeIconProvider.TYPE.PipeRobotStation.ordinal()));
break; break;
case Reserved: case Reserved:
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStationReserved.ordinal()); .getIcon(PipeIconProvider.TYPE.PipeRobotStationReserved.ordinal()));
break; break;
case Linked: case Linked:
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStationLinked.ordinal()); .getIcon(PipeIconProvider.TYPE.PipeRobotStationLinked.ordinal()));
break; break;
} }
@ -213,16 +219,16 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], renderblocks.setRenderBounds(rotated[0][0], rotated[1][0],
rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][0], rotated[0][1], rotated[1][1],
rotated[2][1]); rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
} }
} }
} }
private void pipeRobotStationRenderer(RenderBlocks renderblocks, Block block, PipeRenderState state, int x, int y, int z) { private void pipeRobotStationRenderer(RenderBlocks renderblocks, ITextureStates blockStateMachine, PipeRenderState state, int x, int y, int z) {
//float width = 0.075F; //float width = 0.075F;
pipeRobotStationPartRender (renderblocks, block, state, x, y, z, pipeRobotStationPartRender (renderblocks, blockStateMachine, state, x, y, z,
0.45F, 0.55F, 0.45F, 0.55F,
0.0F, 0.224F, 0.0F, 0.224F,
0.45F, 0.55F); 0.45F, 0.55F);
@ -268,16 +274,16 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
switch (state.robotStationMatrix.getState(direction)) { switch (state.robotStationMatrix.getState(direction)) {
case None: case None:
case Available: case Available:
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStation.ordinal()); .getIcon(PipeIconProvider.TYPE.PipeRobotStation.ordinal()));
break; break;
case Reserved: case Reserved:
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStationReserved.ordinal()); .getIcon(PipeIconProvider.TYPE.PipeRobotStationReserved.ordinal()));
break; break;
case Linked: case Linked:
state.currentTexture = BuildCraftTransport.instance.pipeIconProvider blockStateMachine.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider
.getIcon(PipeIconProvider.TYPE.PipeRobotStationLinked.ordinal()); .getIcon(PipeIconProvider.TYPE.PipeRobotStationLinked.ordinal()));
break; break;
} }
@ -287,7 +293,7 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], renderblocks.setRenderBounds(rotated[0][0], rotated[1][0],
rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][0], rotated[0][1], rotated[1][1],
rotated[2][1]); rotated[2][1]);
renderblocks.renderStandardBlock(block, x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
} }
} }
} }

View file

@ -0,0 +1,57 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*
* Texture State Manager by Itaros(Semion Nadezhdin)
*/
package buildcraft.transport.render;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/*
* This class moves texture management from PipeRenderState
* to be filled while rendering as efficient as possible
*/
@SideOnly(Side.CLIENT)
public final class TextureStateManager {
private IIcon currentTexture;
private IIcon[] textureArray;
private IIcon[] textureArrayCache;
public TextureStateManager(IIcon placeholder) {
currentTexture = placeholder;
textureArrayCache = new IIcon[6];
}
public IIcon[] popArray() {
textureArray = textureArrayCache;
return textureArrayCache; //Thread safety. Seriously.
}
public void pushArray() {
textureArray = null;
}
public IIcon getTexture() {
return currentTexture;
}
public IIcon[] getTextureArray() {
return textureArray;
}
public boolean isSided() {
return textureArray != null;
}
public void set(IIcon icon) {
currentTexture = icon;
}
}