quarry improvements

This commit is contained in:
asiekierka 2015-09-30 14:59:31 +02:00
parent 2ff0d03b97
commit b2ebbcb99b
8 changed files with 132 additions and 100 deletions

View file

@ -224,7 +224,6 @@ public class BuildCraftCore extends BuildCraftMod {
public static IIconProvider iconProvider; public static IIconProvider iconProvider;
public static int blockByEntityModel; public static int blockByEntityModel;
public static int complexBlockModel; public static int complexBlockModel;
public static int legacyPipeModel;
public static int markerModel; public static int markerModel;
public static ITriggerExternal triggerMachineActive = new TriggerMachine(true); public static ITriggerExternal triggerMachineActive = new TriggerMachine(true);
public static ITriggerExternal triggerMachineInactive = new TriggerMachine(false); public static ITriggerExternal triggerMachineInactive = new TriggerMachine(false);

View file

@ -79,7 +79,7 @@ public class BlockFrame extends Block implements IFramePipeConnection {
@Override @Override
public int getRenderType() { public int getRenderType() {
return BuildCraftCore.legacyPipeModel; return BuilderProxy.frameRenderId;
} }
@Override @Override

View file

@ -17,6 +17,7 @@ import buildcraft.core.lib.EntityBlock;
public class BuilderProxy { public class BuilderProxy {
@SidedProxy(clientSide = "buildcraft.builders.BuilderProxyClient", serverSide = "buildcraft.builders.BuilderProxy") @SidedProxy(clientSide = "buildcraft.builders.BuilderProxyClient", serverSide = "buildcraft.builders.BuilderProxy")
public static BuilderProxy proxy; public static BuilderProxy proxy;
public static int frameRenderId;
public void registerClientHook() { public void registerClientHook() {

View file

@ -20,6 +20,7 @@ import buildcraft.builders.render.RenderArchitect;
import buildcraft.builders.render.RenderBuilderTile; import buildcraft.builders.render.RenderBuilderTile;
import buildcraft.builders.render.RenderConstructionMarker; import buildcraft.builders.render.RenderConstructionMarker;
import buildcraft.builders.render.RenderFiller; import buildcraft.builders.render.RenderFiller;
import buildcraft.builders.render.RenderFrame;
import buildcraft.core.lib.EntityBlock; import buildcraft.core.lib.EntityBlock;
import buildcraft.core.lib.render.RenderMultiTESR; import buildcraft.core.lib.render.RenderMultiTESR;
import buildcraft.core.lib.render.RenderVoid; import buildcraft.core.lib.render.RenderVoid;
@ -58,6 +59,9 @@ public class BuilderProxyClient extends BuilderProxy {
})); }));
RenderingRegistry.registerEntityRenderingHandler(EntityMechanicalArm.class, new RenderVoid()); RenderingRegistry.registerEntityRenderingHandler(EntityMechanicalArm.class, new RenderVoid());
frameRenderId = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(frameRenderId, new RenderFrame());
} }

View file

@ -243,7 +243,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
} }
if (miner == null) { if (miner == null) {
// Hmm. // Hmm. Probably shouldn't be mining if there's no miner.
stage = Stage.IDLE; stage = Stage.IDLE;
return; return;
} }
@ -252,7 +252,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
getBattery().useEnergy(rfTaken, rfTaken, false); getBattery().useEnergy(rfTaken, rfTaken, false);
if (miner.hasMined()) { if (miner.hasMined()) {
// Collect any lost items laying around // Collect any lost items laying around.
double[] head = getHead(); 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); AxisAlignedBB axis = AxisAlignedBB.getBoundingBox(head[0] - 2, head[1] - 2, head[2] - 2, head[0] + 3, head[1] + 3, head[2] + 3);
List<EntityItem> result = worldObj.getEntitiesWithinAABB(EntityItem.class, axis); List<EntityItem> result = worldObj.getEntitiesWithinAABB(EntityItem.class, axis);
@ -269,10 +269,25 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
miner.mineStack(mineable); miner.mineStack(mineable);
} }
stage = Stage.IDLE;
miner = null; 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() { protected void idling() {
if (!findTarget(true)) { if (!findTarget(true)) {
@ -573,7 +588,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
if (useDefault) { if (useDefault) {
int xMin, zMin; int xMin, zMin;
int dir = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); int dir = getBlockMetadata();
ForgeDirection o = ForgeDirection.getOrientation(dir > 6 ? 6 : dir).getOpposite(); ForgeDirection o = ForgeDirection.getOrientation(dir > 6 ? 6 : dir).getOpposite();
switch (o) { switch (o) {
@ -613,7 +628,9 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
if (bpt != null) { if (bpt != null) {
builder = new BptBuilderBlueprint(bpt, worldObj, box.xMin, yCoord, box.zMin); builder = new BptBuilderBlueprint(bpt, worldObj, box.xMin, yCoord, box.zMin);
speed = 0;
stage = Stage.BUILDING; stage = Stage.BUILDING;
sendNetworkUpdate();
} }
} }

View file

@ -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;
}
}

View file

@ -87,12 +87,10 @@ public class CoreProxyClient extends CoreProxy {
@Override @Override
public void initializeRendering() { public void initializeRendering() {
BuildCraftCore.blockByEntityModel = RenderingRegistry.getNextAvailableRenderId(); BuildCraftCore.blockByEntityModel = RenderingRegistry.getNextAvailableRenderId();
BuildCraftCore.legacyPipeModel = RenderingRegistry.getNextAvailableRenderId();
BuildCraftCore.markerModel = RenderingRegistry.getNextAvailableRenderId(); BuildCraftCore.markerModel = RenderingRegistry.getNextAvailableRenderId();
BuildCraftCore.complexBlockModel = RenderingRegistry.getNextAvailableRenderId(); BuildCraftCore.complexBlockModel = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new RenderingEntityBlocks()); RenderingRegistry.registerBlockHandler(new RenderingEntityBlocks());
RenderingRegistry.registerBlockHandler(BuildCraftCore.legacyPipeModel, new RenderingEntityBlocks());
RenderingRegistry.registerBlockHandler(new RenderingMarkers()); RenderingRegistry.registerBlockHandler(new RenderingMarkers());
RenderingRegistry.registerBlockHandler(BuildCraftCore.complexBlockModel, new RenderBlockComplex()); RenderingRegistry.registerBlockHandler(BuildCraftCore.complexBlockModel, new RenderBlockComplex());
ClientRegistry.bindTileEntitySpecialRenderer(TilePathMarker.class, new RenderPathMarker()); ClientRegistry.bindTileEntitySpecialRenderer(TilePathMarker.class, new RenderPathMarker());

View file

@ -30,7 +30,6 @@ import buildcraft.core.lib.utils.Utils;
public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler { public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler {
public static HashMap<EntityRenderIndex, IInventoryRenderer> blockByEntityRenders = new HashMap<EntityRenderIndex, IInventoryRenderer>(); public static HashMap<EntityRenderIndex, IInventoryRenderer> blockByEntityRenders = new HashMap<EntityRenderIndex, IInventoryRenderer>();
private static final ResourceLocation BLOCK_TEXTURE = TextureMap.locationBlocksTexture;
public static class EntityRenderIndex { public static class EntityRenderIndex {
Block block; Block block;
@ -60,59 +59,18 @@ public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler {
@Override @Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
if (block.getRenderType() == BuildCraftCore.blockByEntityModel) { if (block.getRenderType() == BuildCraftCore.blockByEntityModel) {
EntityRenderIndex index = new EntityRenderIndex(block, metadata); EntityRenderIndex index = new EntityRenderIndex(block, metadata);
if (blockByEntityRenders.containsKey(index)) { if (blockByEntityRenders.containsKey(index)) {
blockByEntityRenders.get(index).inventoryRender(-0.5, -0.5, -0.5, 0, 0); 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 @Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
if (block.getRenderType() == BuildCraftCore.blockByEntityModel) { if (block.getRenderType() == BuildCraftCore.blockByEntityModel) {
// renderblocks.renderStandardBlock(block, i, j, k); // 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; return true;
@ -127,54 +85,4 @@ public class RenderingEntityBlocks implements ISimpleBlockRenderingHandler {
public int getRenderId() { public int getRenderId() {
return BuildCraftCore.blockByEntityModel; 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);
}
} }