This commit is contained in:
asiekierka 2014-12-16 17:35:42 +01:00
parent a1e355d32a
commit 60af8ac978
3 changed files with 95 additions and 78 deletions

View file

@ -7,5 +7,5 @@ import buildcraft.api.core.render.ITextureStates;
public interface IPipePluggableRenderer {
void renderPluggable(RenderBlocks renderblocks, IPipe pipe, ForgeDirection side,
PipePluggable pipePluggable, ITextureStates blockStateMachine,
int x, int y, int z);
int renderPass, int x, int y, int z);
}

View file

@ -47,6 +47,10 @@ public abstract class PipePluggable implements INBTStoreable, ISerializable {
}
public boolean isSolidOnSide(IPipeContainer pipe, ForgeDirection direction) {
return false;
}
public abstract AxisAlignedBB getBoundingBox(ForgeDirection side);
@SideOnly(Side.CLIENT)

View file

@ -8,6 +8,7 @@
*/
package buildcraft.transport.render;
import com.sun.prism.util.tess.Tess;
import org.lwjgl.opengl.GL11;
import net.minecraft.block.Block;
@ -28,57 +29,12 @@ import buildcraft.transport.PipeIconProvider;
public class FacadeItemRenderer implements IItemRenderer {
private static final float zFightOffset = 1F / 4096F;
private long lastTime = 0L;
private int renderState = 0;
private void renderFacadeItem(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) {
if (lastTime < System.currentTimeMillis()) {
// 12 = LCM(1, 2, 3, 4)
renderState = (renderState + 1) % 12;
lastTime = System.currentTimeMillis() + 1000L;
}
FacadeType type = ((IFacadeItem) item.getItem()).getFacadeType(item);
FacadeState[] states = ItemFacade.getFacadeStates(item);
FacadeState activeState = null;
if (states.length > 0) {
// TODO: Figure out why NEI causes states[] to be of length 0
if (type == FacadeType.Basic) {
activeState = states[0];
} else if (type == FacadeType.Phased) {
activeState = states[renderState % states.length];
}
}
Block block = activeState != null ? activeState.block : null;
int decodedMeta = activeState != null ? activeState.metadata : 0;
ItemStack decodedStack = new ItemStack(block, 1, decodedMeta);
try {
int color = decodedStack.getItem().getColorFromItemStack(decodedStack, 0);
RenderUtils.setGLColorFromInt(color);
} catch (Throwable error) {
}
Tessellator tessellator = Tessellator.instance;
if (tryGetBlockIcon(block, 0, decodedMeta) == null) {
return;
}
// Render Facade
GL11.glPushMatrix();
// Enable glBlending for transparency
if (block != null && block.getRenderBlockPass() > 0) {
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
}
render.setRenderBounds(0F, 0F, 1F - 1F / 16F, 1F, 1F, 1F);
GL11.glTranslatef(translateX, translateY, translateZ);
private void drawCube(Tessellator tessellator, RenderBlocks render, Block block, int decodedMeta) {
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1F, 0.0F);
render.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 0, decodedMeta));
@ -103,6 +59,61 @@ public class FacadeItemRenderer implements IItemRenderer {
tessellator.setNormal(1.0F, 0.0F, 0.0F);
render.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 5, decodedMeta));
tessellator.draw();
}
private void renderFacadeItem(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) {
if (lastTime < System.currentTimeMillis()) {
// 12 = LCM(1, 2, 3, 4)
renderState = (renderState + 1) % 12;
lastTime = System.currentTimeMillis() + 1000L;
}
FacadeType type = ((IFacadeItem) item.getItem()).getFacadeType(item);
FacadeState[] states = ItemFacade.getFacadeStates(item);
FacadeState activeState = null;
if (states.length > 0) {
// TODO: Figure out why NEI causes states[] to be of length 0
if (type == FacadeType.Basic) {
activeState = states[0];
} else if (type == FacadeType.Phased) {
activeState = states[renderState % states.length];
}
}
Block block = activeState != null ? activeState.block : null;
int decodedMeta = activeState != null ? activeState.metadata : 0;
boolean hollow = activeState != null ? activeState.hollow : false;
ItemStack decodedStack = new ItemStack(block, 1, decodedMeta);
try {
int color = decodedStack.getItem().getColorFromItemStack(decodedStack, 0);
RenderUtils.setGLColorFromInt(color);
} catch (Throwable error) {
}
Tessellator tessellator = Tessellator.instance;
if (tryGetBlockIcon(block, 0, decodedMeta) == null) {
return;
}
// Render Facade
GL11.glPushMatrix();
// Enable glBlending for transparency
if (block != null && block.getRenderBlockPass() > 0) {
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
}
if (hollow) {
// TODO
} else {
render.setRenderBounds(0F, 0F, 1F - 1F / 16F, 1F, 1F, 1F);
GL11.glTranslatef(translateX, translateY, translateZ);
drawCube(tessellator, render, block, decodedMeta);
}
// Disable blending
if (block != null && block.getRenderBlockPass() > 0) {
@ -114,38 +125,40 @@ public class FacadeItemRenderer implements IItemRenderer {
RenderUtils.setGLColorFromInt(0xFFFFFF);
// Render StructurePipe
block = BuildCraftTransport.genericPipeBlock;
IIcon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure pipe
if (!hollow) {
block = BuildCraftTransport.genericPipeBlock;
IIcon textureID = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal()); // Structure pipe
block.setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS - 1F / 16F);
block.setBlockBoundsForItemRender();
render.setRenderBoundsFromBlock(block);
GL11.glTranslatef(translateX, translateY, translateZ + 0.25F);
block.setBlockBounds(CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MAX_POS - 1F / 16F);
block.setBlockBoundsForItemRender();
render.setRenderBoundsFromBlock(block);
GL11.glTranslatef(translateX, translateY, translateZ + 0.25F);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -0F, 0.0F);
render.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
render.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1F);
render.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
render.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(-1F, 0.0F, 0.0F);
render.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
render.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -0F, 0.0F);
render.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
render.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1F);
render.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
render.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(-1F, 0.0F, 0.0F);
render.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
render.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, textureID);
tessellator.draw();
}
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}