More intelligent pipe side rendering

This commit is contained in:
CovertJaguar 2013-08-16 02:27:23 -07:00
parent 8a12218085
commit 8d7b50fa22
2 changed files with 62 additions and 44 deletions

View file

@ -65,6 +65,7 @@ public class BlockGenericPipe extends BlockContainer {
}
private static Random rand = new Random();
private boolean skippedFirstIconRegister;
private char renderAxis = 'a';
/* Defined subprograms ************************************************* */
public BlockGenericPipe(int i) {
@ -95,10 +96,20 @@ public class BlockGenericPipe extends BlockContainer {
public boolean renderAsNormalBlock() {
return false;
}
public void setRenderAxis(char axis) {
this.renderAxis = axis;
}
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side) {
if (renderAxis == 'x')
return side == 4 || side == 5;
if (renderAxis == 'y')
return side == 0 || side == 1;
if (renderAxis == 'z')
return side == 2 || side == 3;
return true;
}
@ -122,39 +133,39 @@ public class BlockGenericPipe extends BlockContainer {
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
TileEntity tile1 = world.getBlockTileEntity(i, j, k);
TileGenericPipe tileG = (TileGenericPipe) tile1;
if (tile1 instanceof TileGenericPipe) {
TileGenericPipe tileG = (TileGenericPipe) tile1;
if (tileG.isPipeConnected(ForgeDirection.WEST)) {
setBlockBounds(0.0F, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.WEST)) {
setBlockBounds(0.0F, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.EAST)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, 1.0F, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.EAST)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, 1.0F, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.DOWN)) {
setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.DOWN)) {
setBlockBounds(Utils.pipeMinPos, 0.0F, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.UP)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.UP)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, 1.0F, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.NORTH)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, 0.0F, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.NORTH)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, 0.0F, Utils.pipeMaxPos, Utils.pipeMaxPos, Utils.pipeMaxPos);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.SOUTH)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG.isPipeConnected(ForgeDirection.SOUTH)) {
setBlockBounds(Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMinPos, Utils.pipeMaxPos, Utils.pipeMaxPos, 1.0F);
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
if (tileG != null) {
float facadeThickness = PipeWorldRenderer.facadeThickness;
if (tileG.hasFacade(ForgeDirection.EAST)) {
@ -187,7 +198,6 @@ public class BlockGenericPipe extends BlockContainer {
super.addCollisionBoxesToList(world, i, j, k, axisalignedbb, arraylist, par7Entity);
}
}
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
@ -259,7 +269,7 @@ public class BlockGenericPipe extends BlockContainer {
}
}
public RaytraceResult doRayTrace(World world, int x, int y, int z, EntityPlayer entityPlayer) {
private RaytraceResult doRayTrace(World world, int x, int y, int z, EntityPlayer entityPlayer) {
double pitch = Math.toRadians(entityPlayer.rotationPitch);
double yaw = Math.toRadians(entityPlayer.rotationYaw);
@ -279,28 +289,28 @@ public class BlockGenericPipe extends BlockContainer {
return doRayTrace(world, x, y, z, origin, direction);
}
public RaytraceResult doRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
private RaytraceResult doRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
float xMin = Utils.pipeMinPos, xMax = Utils.pipeMaxPos, yMin = Utils.pipeMinPos, yMax = Utils.pipeMaxPos, zMin = Utils.pipeMinPos, zMax = Utils.pipeMaxPos;
TileEntity pipeTileEntity = world.getBlockTileEntity(x, y, z);
TileGenericPipe tileG = null;
if(pipeTileEntity instanceof TileGenericPipe)
tileG = (TileGenericPipe)pipeTileEntity;
if(tileG == null)
if (pipeTileEntity instanceof TileGenericPipe)
tileG = (TileGenericPipe) pipeTileEntity;
if (tileG == null)
return null;
Pipe pipe = tileG.pipe;
if (!isValid(pipe))
return null;
return null;
/**
* pipe hits along x, y, and z axis, gate (all 6 sides) [and
* wires+facades]
*/
MovingObjectPosition[] hits = new MovingObjectPosition[]{null, null, null, null, null, null, null, null, null};
MovingObjectPosition[] hits = new MovingObjectPosition[9];
boolean needAxisCheck = false;
boolean needCenterCheck = true;
@ -514,6 +524,7 @@ public class BlockGenericPipe extends BlockContainer {
return list;
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileGenericPipe();
}
@ -754,6 +765,7 @@ public class BlockGenericPipe extends BlockContainer {
@SuppressWarnings({"all"})
@SideOnly(Side.CLIENT)
@Override
public Icon getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l) {
TileEntity tile = iblockaccess.getBlockTileEntity(i, j, k);

View file

@ -79,7 +79,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
return target;
}
private void renderAllFaceExeptAxe(RenderBlocks renderblocks, Block block, Icon icon, int x, int y, int z, char axe) {
private void renderAllFaceExeptAxe(RenderBlocks renderblocks, BlockGenericPipe block, Icon icon, int x, int y, int z, char axe) {
float minX = (float) renderblocks.renderMinX;
float minY = (float) renderblocks.renderMinY;
float minZ = (float) renderblocks.renderMinZ;
@ -100,22 +100,28 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
}
}
private void renderTwoWayXFace(RenderBlocks renderblocks, Block block, Icon icon, int xCoord, int yCoord, int zCoord, float minY, float minZ, float maxY, float maxZ, float x) {
private void renderTwoWayXFace(RenderBlocks renderblocks, BlockGenericPipe block, Icon icon, int xCoord, int yCoord, int zCoord, float minY, float minZ, float maxY, float maxZ, float x) {
renderblocks.setRenderBounds(x, minY, minZ, x, maxY, maxZ);
block.setRenderAxis('x');
renderblocks.renderStandardBlock(block, xCoord, yCoord, zCoord);
block.setRenderAxis('a');
}
private void renderTwoWayYFace(RenderBlocks renderblocks, Block block, Icon icon, int xCoord, int yCoord, int zCoord, float minX, float minZ, float maxX, float maxZ, float y) {
private void renderTwoWayYFace(RenderBlocks renderblocks, BlockGenericPipe block, Icon icon, int xCoord, int yCoord, int zCoord, float minX, float minZ, float maxX, float maxZ, float y) {
renderblocks.setRenderBounds(minX, y, minZ, maxX, y, maxZ);
block.setRenderAxis('y');
renderblocks.renderStandardBlock(block, xCoord, yCoord, zCoord);
block.setRenderAxis('a');
}
private void renderTwoWayZFace(RenderBlocks renderblocks, Block block, Icon icon, int xCoord, int yCoord, int zCoord, float minX, float minY, float maxX, float maxY, float z) {
private void renderTwoWayZFace(RenderBlocks renderblocks, BlockGenericPipe block, Icon icon, int xCoord, int yCoord, int zCoord, float minX, float minY, float maxX, float maxY, float z) {
renderblocks.setRenderBounds(minX, minY, z, maxX, maxY, z);
block.setRenderAxis('z');
renderblocks.renderStandardBlock(block, xCoord, yCoord, zCoord);
block.setRenderAxis('a');
}
public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, Block block, IPipeRenderState renderState, int x, int y, int z) {
public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, BlockGenericPipe block, IPipeRenderState renderState, int x, int y, int z) {
float minSize = Utils.pipeMinPos;
float maxSize = Utils.pipeMaxPos;
@ -560,7 +566,7 @@ public class PipeWorldRenderer implements ISimpleBlockRenderingHandler {
if (tile instanceof IPipeRenderState) {
IPipeRenderState pipeTile = (IPipeRenderState) tile;
renderPipe(renderer, world, block, pipeTile, x, y, z);
renderPipe(renderer, world, (BlockGenericPipe) block, pipeTile, x, y, z);
}
return true;
}