Improve Facade Rendering + Interaction

This commit is contained in:
CovertJaguar 2013-10-20 00:36:37 -07:00
parent d6e0277b7d
commit 93f9dceb90
5 changed files with 119 additions and 60 deletions

View file

@ -81,11 +81,12 @@ public class BlockGenericPipe extends BlockContainer {
private static final ForgeDirection[] DIR_VALUES = ForgeDirection.values();
private static Random rand = new Random();
private boolean skippedFirstIconRegister;
private char renderAxis = 'a';
private boolean[] renderSide = new boolean[6];
/* Defined subprograms ************************************************* */
public BlockGenericPipe(int i) {
super(i, Material.glass);
setRenderAllSides();
}
@Override
@ -114,19 +115,33 @@ public class BlockGenericPipe extends BlockContainer {
}
public void setRenderAxis(char axis) {
this.renderAxis = axis;
Arrays.fill(renderSide, false);
if (axis == 'x') {
renderSide[4] = true;
renderSide[5] = true;
}
if (axis == 'y') {
renderSide[0] = true;
renderSide[1] = true;
}
if (axis == 'z') {
renderSide[2] = true;
renderSide[3] = true;
}
}
public final void setRenderAllSides() {
Arrays.fill(renderSide, true);
}
public void setRenderSide(ForgeDirection side, boolean render) {
renderSide[side.ordinal()] = render;
}
@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;
return renderSide[side];
}
@Override
@ -583,11 +598,11 @@ public class BlockGenericPipe extends BlockContainer {
if (rayTraceResult != null && rayTraceResult.boundingBox != null) {
switch (rayTraceResult.hitPart) {
case Gate:
Pipe pipe = getPipe(world, x, y, z);
return pipe.gate.getGateItem();
case Plug:
return new ItemStack(BuildCraftTransport.plugItem);
case Gate:
Pipe pipe = getPipe(world, x, y, z);
return pipe.gate.getGateItem();
case Plug:
return new ItemStack(BuildCraftTransport.plugItem);
}
}
return super.getPickBlock(target, world, x, y, z);
@ -772,15 +787,17 @@ public class BlockGenericPipe extends BlockContainer {
}
private boolean addOrStripFacade(World world, int x, int y, int z, EntityPlayer player, ForgeDirection side, Pipe pipe) {
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);
if (player.isSneaking()) {
RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, player);
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Facade) {
if (stripFacade(pipe, rayTraceResult.sideHit))
return true;
}
}
if (addFacade(player, pipe, side))
return true;
if (rayTraceResult != null && rayTraceResult.hitPart == Part.Pipe) {
if (addFacade(player, pipe, rayTraceResult.sideHit != null && rayTraceResult.sideHit != ForgeDirection.UNKNOWN ? rayTraceResult.sideHit : side))
return true;
}
return false;
}
@ -874,11 +891,13 @@ public class BlockGenericPipe extends BlockContainer {
@SuppressWarnings({"all"})
@SideOnly(Side.CLIENT)
@Override
public Icon getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l) {
public Icon getBlockTexture(IBlockAccess iblockaccess, int x, int y, int z, int side) {
TileEntity tile = iblockaccess.getBlockTileEntity(i, j, k);
TileEntity tile = iblockaccess.getBlockTileEntity(x, y, z);
if (!(tile instanceof IPipeRenderState))
return null;
if (((IPipeRenderState) tile).getRenderState().textureArray != null)
return ((IPipeRenderState) tile).getRenderState().textureArray[side];
return ((IPipeRenderState) tile).getRenderState().currentTexture;
// Pipe pipe = getPipe(iblockaccess, i, j, k);

View file

@ -1,6 +1,7 @@
package buildcraft.transport;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.Position;
import buildcraft.api.recipes.AssemblyRecipe;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemBuildCraft;
@ -17,12 +18,15 @@ import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public class ItemFacade extends ItemBuildCraft {
@ -68,30 +72,26 @@ public class ItemFacade extends ItemBuildCraft {
}
}
// @Override
// public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
// if (worldObj.isRemote)
// return false;
// TileEntity tile = worldObj.getBlockTileEntity(x, y, z);
// if (!(tile instanceof TileGenericPipe))
// return false;
// TileGenericPipe pipeTile = (TileGenericPipe) tile;
//
// if (player.isSneaking()) { // Strip facade
// if (!pipeTile.hasFacade(ForgeDirection.VALID_DIRECTIONS[side]))
// return false;
// pipeTile.dropFacade(ForgeDirection.VALID_DIRECTIONS[side]);
// return true;
// } else {
// if (((TileGenericPipe) tile).addFacade(ForgeDirection.values()[side], ItemFacade.getBlockId(stack), ItemFacade.getMetaData(stack))) {
// if (!player.capabilities.isCreativeMode) {
// stack.stackSize--;
// }
// return true;
// }
// return false;
// }
// }
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (worldObj.isRemote)
return false;
Position pos = new Position(x, y, z, ForgeDirection.getOrientation(side));
pos.moveForwards(1.0);
TileEntity tile = worldObj.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (!(tile instanceof TileGenericPipe))
return false;
TileGenericPipe pipeTile = (TileGenericPipe) tile;
if (pipeTile.addFacade(ForgeDirection.getOrientation(side).getOpposite(), ItemFacade.getBlockId(stack), ItemFacade.getMetaData(stack))) {
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
return true;
}
return false;
}
public static void initialize() {
for (Field f : Block.class.getDeclaredFields()) {
@ -253,7 +253,7 @@ public class ItemFacade extends ItemBuildCraft {
public static ItemStack getStack(Block block, int metadata) {
return getStack(block.blockID, metadata);
}
public static ItemStack getStack(int blockID, int metadata) {
ItemStack stack = new ItemStack(BuildCraftTransport.facadeItem, 1, 0);
NBTTagCompound nbt = new NBTTagCompound("tag");

View file

@ -28,6 +28,8 @@ public class PipeRenderState implements IClientState {
*/
@SideOnly(Side.CLIENT)
public Icon currentTexture;
@SideOnly(Side.CLIENT)
public Icon[] textureArray;
public void setHasGate(boolean value) {
if (hasGate != value) {

View file

@ -8,14 +8,12 @@
*/
package buildcraft.transport;
import net.minecraft.item.ItemStack;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class TransportConstants {
public static final float FACADE_THICKNESS = 1F / 16F;
public static final float FACADE_THICKNESS = 2F / 16F;
public static final float PIPE_NORMAL_SPEED = 0.01F;
}

View file

@ -22,9 +22,6 @@ import net.minecraftforge.common.ForgeDirection;
public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
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;
@ -148,27 +145,60 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
}
private void pipeFacadeRenderer(RenderBlocks renderblocks, Block block, PipeRenderState state, int x, int y, int z) {
private void pipeFacadeRenderer(RenderBlocks renderblocks, BlockGenericPipe block, PipeRenderState state, int x, int y, int z) {
float zFightOffset = 1F / 4096F;
float[][] zeroState = new float[3][2];
// X START - END
zeroState[0][0] = 0.0F - zFightOffset / 2;
zeroState[0][1] = 1.0F + zFightOffset / 2;
zeroState[0][0] = 0.0F;
zeroState[0][1] = 1.0F;
// Y START - END
zeroState[1][0] = 0.0F - zFightOffset;
zeroState[1][0] = 0.0F;
zeroState[1][1] = TransportConstants.FACADE_THICKNESS;
// Z START - END
zeroState[2][0] = 0.0F;
zeroState[2][1] = 1.0F;
float[] xOffsets = new float[6];
xOffsets[0] = zFightOffset;
xOffsets[1] = zFightOffset;
xOffsets[2] = 0;
xOffsets[3] = 0;
xOffsets[4] = 0;
xOffsets[5] = 0;
float[] yOffsets = new float[6];
yOffsets[0] = 0;
yOffsets[1] = 0;
yOffsets[2] = zFightOffset;
yOffsets[3] = zFightOffset;
yOffsets[4] = 0;
yOffsets[5] = 0;
float[] zOffsets = new float[6];
zOffsets[0] = zFightOffset;
zOffsets[1] = zFightOffset;
zOffsets[2] = 0;
zOffsets[3] = 0;
zOffsets[4] = 0;
zOffsets[5] = 0;
state.textureArray = new Icon[6];
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
int facadeId = state.facadeMatrix.getFacadeBlockId(direction);
if (facadeId != 0) {
Block renderBlock = Block.blocksList[facadeId];
int renderMeta = state.facadeMatrix.getFacadeMetaId(direction);
state.currentTexture = renderBlock.getIcon(direction.ordinal(), renderMeta);
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
state.textureArray[side.ordinal()] = renderBlock.getIcon(side.ordinal(), renderMeta);
if (side == direction || side == direction.getOpposite())
block.setRenderSide(side, true);
else
block.setRenderSide(side, state.facadeMatrix.getFacadeBlockId(side) == 0);
}
try {
BlockGenericPipe.facadeRenderColor = Item.itemsList[state.facadeMatrix.getFacadeBlockId(direction)].getColorFromItemStack(new ItemStack(facadeId, 1, renderMeta), 0);
@ -190,16 +220,18 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
// Hollow facade
if (state.pipeConnectionMatrix.isConnected(direction)) {
float[][] rotated = MatrixTranformations.deepClone(zeroState);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset;
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset;
rotated[2][0] = 0.0F;
rotated[2][1] = CoreConstants.PIPE_MIN_POS - zFightOffset;
rotated[1][0] -= zFightOffset / 2;
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.renderStandardBlock(block, x, y, z);
rotated = MatrixTranformations.deepClone(zeroState);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset;
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset;
rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset;
rotated[1][0] -= zFightOffset / 2;
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.renderStandardBlock(block, x, y, z);
@ -207,7 +239,6 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
rotated = MatrixTranformations.deepClone(zeroState);
rotated[0][0] = 0.0F;
rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset;
rotated[1][1] -= zFightOffset;
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.renderStandardBlock(block, x, y, z);
@ -215,14 +246,20 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
rotated = MatrixTranformations.deepClone(zeroState);
rotated[0][0] = CoreConstants.PIPE_MAX_POS + zFightOffset;
rotated[0][1] = 1F;
rotated[1][1] -= zFightOffset;
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.renderStandardBlock(block, x, y, z);
} else { // Solid facade
float[][] rotated = MatrixTranformations.deepClone(zeroState);
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] + xOffsets[direction.ordinal()],
rotated[1][0] + yOffsets[direction.ordinal()],
rotated[2][0] + zOffsets[direction.ordinal()],
rotated[0][1] + xOffsets[direction.ordinal()],
rotated[1][1] + yOffsets[direction.ordinal()],
rotated[2][1] + zOffsets[direction.ordinal()]);
renderblocks.renderStandardBlock(block, x, y, z);
}
@ -239,6 +276,9 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
BlockGenericPipe.facadeRenderColor = -1;
}
state.textureArray = null;
block.setRenderAllSides();
// X START - END
zeroState[0][0] = CoreConstants.PIPE_MIN_POS;
zeroState[0][1] = CoreConstants.PIPE_MAX_POS;