diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index cbace392..2d057d89 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -224,7 +224,6 @@ public class BuildCraftCore extends BuildCraftMod { public static IIconProvider iconProvider; public static int blockByEntityModel; public static int complexBlockModel; - public static int legacyPipeModel; public static int markerModel; public static ITriggerExternal triggerMachineActive = new TriggerMachine(true); public static ITriggerExternal triggerMachineInactive = new TriggerMachine(false); diff --git a/common/buildcraft/builders/BlockFrame.java b/common/buildcraft/builders/BlockFrame.java index 3b84a1c7..977e83dc 100644 --- a/common/buildcraft/builders/BlockFrame.java +++ b/common/buildcraft/builders/BlockFrame.java @@ -79,7 +79,7 @@ public class BlockFrame extends Block implements IFramePipeConnection { @Override public int getRenderType() { - return BuildCraftCore.legacyPipeModel; + return BuilderProxy.frameRenderId; } @Override diff --git a/common/buildcraft/builders/BuilderProxy.java b/common/buildcraft/builders/BuilderProxy.java index 2927c667..1cc383d7 100644 --- a/common/buildcraft/builders/BuilderProxy.java +++ b/common/buildcraft/builders/BuilderProxy.java @@ -17,6 +17,7 @@ import buildcraft.core.lib.EntityBlock; public class BuilderProxy { @SidedProxy(clientSide = "buildcraft.builders.BuilderProxyClient", serverSide = "buildcraft.builders.BuilderProxy") public static BuilderProxy proxy; + public static int frameRenderId; public void registerClientHook() { diff --git a/common/buildcraft/builders/BuilderProxyClient.java b/common/buildcraft/builders/BuilderProxyClient.java index bf539610..a280f6dc 100644 --- a/common/buildcraft/builders/BuilderProxyClient.java +++ b/common/buildcraft/builders/BuilderProxyClient.java @@ -20,6 +20,7 @@ import buildcraft.builders.render.RenderArchitect; import buildcraft.builders.render.RenderBuilderTile; import buildcraft.builders.render.RenderConstructionMarker; import buildcraft.builders.render.RenderFiller; +import buildcraft.builders.render.RenderFrame; import buildcraft.core.lib.EntityBlock; import buildcraft.core.lib.render.RenderMultiTESR; import buildcraft.core.lib.render.RenderVoid; @@ -58,6 +59,9 @@ public class BuilderProxyClient extends BuilderProxy { })); RenderingRegistry.registerEntityRenderingHandler(EntityMechanicalArm.class, new RenderVoid()); + + frameRenderId = RenderingRegistry.getNextAvailableRenderId(); + RenderingRegistry.registerBlockHandler(frameRenderId, new RenderFrame()); } diff --git a/common/buildcraft/builders/TileQuarry.java b/common/buildcraft/builders/TileQuarry.java index ae853df1..e0514c11 100644 --- a/common/buildcraft/builders/TileQuarry.java +++ b/common/buildcraft/builders/TileQuarry.java @@ -243,7 +243,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI } if (miner == null) { - // Hmm. + // Hmm. Probably shouldn't be mining if there's no miner. stage = Stage.IDLE; return; } @@ -252,7 +252,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI getBattery().useEnergy(rfTaken, rfTaken, false); if (miner.hasMined()) { - // Collect any lost items laying around + // Collect any lost items laying around. double[] head = getHead(); AxisAlignedBB axis = AxisAlignedBB.getBoundingBox(head[0] - 2, head[1] - 2, head[2] - 2, head[0] + 3, head[1] + 3, head[2] + 3); List result = worldObj.getEntitiesWithinAABB(EntityItem.class, axis); @@ -269,11 +269,26 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI miner.mineStack(mineable); } - stage = Stage.IDLE; miner = null; + + if (!findFrame()) { + initializeBlueprintBuilder(); + stage = Stage.BUILDING; + } else { + stage = Stage.IDLE; + } } } + protected boolean findFrame() { + int dir = getBlockMetadata(); + ForgeDirection o = ForgeDirection.getOrientation(dir > 6 ? 6 : dir).getOpposite(); + if (o == ForgeDirection.UNKNOWN) { + return true; + } + return worldObj.getBlock(xCoord + o.offsetX, yCoord + o.offsetY, zCoord + o.offsetZ) == BuildCraftBuilders.frameBlock; + } + protected void idling() { if (!findTarget(true)) { // I believe the issue is box going null becuase of bad chunkloader positioning @@ -573,7 +588,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI if (useDefault) { int xMin, zMin; - int dir = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); + int dir = getBlockMetadata(); ForgeDirection o = ForgeDirection.getOrientation(dir > 6 ? 6 : dir).getOpposite(); switch (o) { @@ -613,7 +628,9 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI if (bpt != null) { builder = new BptBuilderBlueprint(bpt, worldObj, box.xMin, yCoord, box.zMin); + speed = 0; stage = Stage.BUILDING; + sendNetworkUpdate(); } } diff --git a/common/buildcraft/builders/render/RenderFrame.java b/common/buildcraft/builders/render/RenderFrame.java new file mode 100644 index 00000000..35d8505e --- /dev/null +++ b/common/buildcraft/builders/render/RenderFrame.java @@ -0,0 +1,105 @@ +package buildcraft.builders.render; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.world.IBlockAccess; + +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; + +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.BuildCraftBuilders; +import buildcraft.builders.BuilderProxy; +import buildcraft.core.CoreConstants; +import buildcraft.core.lib.render.FakeBlock; +import buildcraft.core.lib.render.RenderUtils; + +public class RenderFrame implements ISimpleBlockRenderingHandler { + private void renderTwoWayBlock(RenderBlocks renderblocks, FakeBlock stateHost, int x, int y, int z, float[] dim, int mask) { + assert mask != 0; + + stateHost.setRenderMask(mask); + renderblocks.setRenderBounds(dim[2], dim[0], dim[1], dim[5], dim[3], dim[4]); + renderblocks.renderStandardBlockWithColorMultiplier(stateHost, x, y, z, 1.0f, 1.0f, 1.0f); + + stateHost.setRenderMask((mask & 0x15) << 1 | (mask & 0x2a) >> 1); // pairwise swapped mask + renderblocks.setRenderBounds(dim[5], dim[3], dim[4], dim[2], dim[0], dim[1]); + renderblocks.renderStandardBlockWithColorMultiplier(stateHost, x, y, z, 0.8f, 0.8f, 0.8f); + + stateHost.setRenderAllSides(); + } + + private void resetToCenterDimensions(float[] dim) { + for (int i = 0; i < 3; i++) { + dim[i] = CoreConstants.PIPE_MIN_POS; + dim[i + 3] = CoreConstants.PIPE_MAX_POS; + } + } + + @Override + public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { + renderer.setRenderBounds(0.25F, 0.0F, 0.25F, 0.75F, 1.0F, 0.75F); + RenderUtils.drawBlockItem(renderer, Tessellator.instance, block, metadata); + } + + @Override + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { + FakeBlock fakeBlock = FakeBlock.INSTANCE; + fakeBlock.getTextureState().set(block.getIcon(0, 0)); + + int connectivity = 0; + int connections = 0; + + float[] dim = new float[6]; + resetToCenterDimensions(dim); + + for (int i = 0; i < 6; i++) { + ForgeDirection d = ForgeDirection.getOrientation(i); + if (world.getBlock(x + d.offsetX, y + d.offsetY, z + d.offsetZ) == block) { + connectivity |= 1 << i; + connections++; + } + } + + if (connections != 2) { + renderTwoWayBlock(renderer, fakeBlock, x, y, z, dim, 0x3f); + } else { + renderTwoWayBlock(renderer, fakeBlock, x, y, z, dim, connectivity ^ 0x3f); + } + + // render the connecting pipe faces + for (int dir = 0; dir < 6; dir++) { + int mask = 1 << dir; + + if ((connectivity & mask) == 0) { + continue; // no connection towards dir + } + + // center piece offsets + resetToCenterDimensions(dim); + + // extend block towards dir as it's connected to there + dim[dir / 2] = dir % 2 == 0 ? 0 : CoreConstants.PIPE_MAX_POS; + dim[dir / 2 + 3] = dir % 2 == 0 ? CoreConstants.PIPE_MIN_POS : 1; + + // the mask points to all faces perpendicular to dir, i.e. dirs 0+1 -> mask 111100, 1+2 -> 110011, 3+5 -> 001111 + int renderMask = (3 << (dir & 0x6)) ^ 0x3f; + renderTwoWayBlock(renderer, fakeBlock, x, y, z, dim, renderMask); + } + + renderer.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + return true; + } + + @Override + public boolean shouldRender3DInInventory(int modelId) { + return true; + } + + @Override + public int getRenderId() { + return BuilderProxy.frameRenderId; + } +} diff --git a/common/buildcraft/core/proxy/CoreProxyClient.java b/common/buildcraft/core/proxy/CoreProxyClient.java index 2c75a136..fa63d72b 100644 --- a/common/buildcraft/core/proxy/CoreProxyClient.java +++ b/common/buildcraft/core/proxy/CoreProxyClient.java @@ -87,12 +87,10 @@ public class CoreProxyClient extends CoreProxy { @Override public void initializeRendering() { BuildCraftCore.blockByEntityModel = RenderingRegistry.getNextAvailableRenderId(); - BuildCraftCore.legacyPipeModel = RenderingRegistry.getNextAvailableRenderId(); BuildCraftCore.markerModel = RenderingRegistry.getNextAvailableRenderId(); BuildCraftCore.complexBlockModel = RenderingRegistry.getNextAvailableRenderId(); RenderingRegistry.registerBlockHandler(new RenderingEntityBlocks()); - RenderingRegistry.registerBlockHandler(BuildCraftCore.legacyPipeModel, new RenderingEntityBlocks()); RenderingRegistry.registerBlockHandler(new RenderingMarkers()); RenderingRegistry.registerBlockHandler(BuildCraftCore.complexBlockModel, new RenderBlockComplex()); ClientRegistry.bindTileEntitySpecialRenderer(TilePathMarker.class, new RenderPathMarker()); diff --git a/common/buildcraft/core/render/RenderingEntityBlocks.java b/common/buildcraft/core/render/RenderingEntityBlocks.java index 2be55848..c9583d79 100644 --- a/common/buildcraft/core/render/RenderingEntityBlocks.java +++ b/common/buildcraft/core/render/RenderingEntityBlocks.java @@ -30,7 +30,6 @@ import buildcraft.core.lib.utils.Utils; public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler { public static HashMap blockByEntityRenders = new HashMap(); - private static final ResourceLocation BLOCK_TEXTURE = TextureMap.locationBlocksTexture; public static class EntityRenderIndex { Block block; @@ -60,59 +59,18 @@ public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler { @Override public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { - if (block.getRenderType() == BuildCraftCore.blockByEntityModel) { - EntityRenderIndex index = new EntityRenderIndex(block, metadata); if (blockByEntityRenders.containsKey(index)) { blockByEntityRenders.get(index).inventoryRender(-0.5, -0.5, -0.5, 0, 0); } - - } else if (block.getRenderType() == BuildCraftCore.legacyPipeModel) { - Tessellator tessellator = Tessellator.instance; - - block.setBlockBounds(CoreConstants.PIPE_MIN_POS, 0.0F, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, 1.0F, CoreConstants.PIPE_MAX_POS); - renderer.setRenderBoundsFromBlock(block); - block.setBlockBoundsForItemRender(); - GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - tessellator.startDrawingQuads(); - tessellator.setNormal(0.0F, -1F, 0.0F); - renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(0, metadata)); - tessellator.draw(); - tessellator.startDrawingQuads(); - tessellator.setNormal(0.0F, 1.0F, 0.0F); - renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(1, metadata)); - tessellator.draw(); - tessellator.startDrawingQuads(); - tessellator.setNormal(0.0F, 0.0F, -1F); - renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(2, metadata)); - tessellator.draw(); - tessellator.startDrawingQuads(); - tessellator.setNormal(0.0F, 0.0F, 1.0F); - renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(3, metadata)); - tessellator.draw(); - tessellator.startDrawingQuads(); - tessellator.setNormal(-1F, 0.0F, 0.0F); - renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(4, metadata)); - tessellator.draw(); - tessellator.startDrawingQuads(); - tessellator.setNormal(1.0F, 0.0F, 0.0F); - renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(5, metadata)); - tessellator.draw(); - GL11.glTranslatef(0.5F, 0.5F, 0.5F); - block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } } @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { - if (block.getRenderType() == BuildCraftCore.blockByEntityModel) { // renderblocks.renderStandardBlock(block, i, j, k); - } else if (block.getRenderType() == BuildCraftCore.legacyPipeModel) { - Minecraft.getMinecraft().renderEngine.bindTexture(BLOCK_TEXTURE); - legacyPipeRender(renderer, world, x, y, z, block, modelId); - } return true; @@ -127,54 +85,4 @@ public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler { public int getRenderId() { return BuildCraftCore.blockByEntityModel; } - - /* LEGACY PIPE RENDERING and quarry frames! */ - private void legacyPipeRender(RenderBlocks renderblocks, IBlockAccess iblockaccess, int i, int j, int k, Block block, int l) { - float minSize = CoreConstants.PIPE_MIN_POS; - float maxSize = CoreConstants.PIPE_MAX_POS; - - block.setBlockBounds(minSize, minSize, minSize, maxSize, maxSize, maxSize); - renderblocks.setRenderBoundsFromBlock(block); - renderblocks.renderStandardBlock(block, i, j, k); - - if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i - 1, j, k)) { - block.setBlockBounds(0.0F, minSize, minSize, minSize, maxSize, maxSize); - renderblocks.setRenderBoundsFromBlock(block); - renderblocks.renderStandardBlock(block, i, j, k); - } - - if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i + 1, j, k)) { - block.setBlockBounds(maxSize, minSize, minSize, 1.0F, maxSize, maxSize); - renderblocks.setRenderBoundsFromBlock(block); - renderblocks.renderStandardBlock(block, i, j, k); - } - - if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i, j - 1, k)) { - block.setBlockBounds(minSize, 0.0F, minSize, maxSize, minSize, maxSize); - renderblocks.setRenderBoundsFromBlock(block); - renderblocks.renderStandardBlock(block, i, j, k); - } - - if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i, j + 1, k)) { - block.setBlockBounds(minSize, maxSize, minSize, maxSize, 1.0F, maxSize); - renderblocks.setRenderBoundsFromBlock(block); - renderblocks.renderStandardBlock(block, i, j, k); - } - - if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i, j, k - 1)) { - block.setBlockBounds(minSize, minSize, 0.0F, maxSize, maxSize, minSize); - renderblocks.setRenderBoundsFromBlock(block); - renderblocks.renderStandardBlock(block, i, j, k); - } - - if (Utils.checkLegacyPipesConnections(iblockaccess, i, j, k, i, j, k + 1)) { - block.setBlockBounds(minSize, minSize, maxSize, maxSize, maxSize, 1.0F); - renderblocks.setRenderBoundsFromBlock(block); - renderblocks.renderStandardBlock(block, i, j, k); - } - - block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); - } - - }