Search in sources :

Example 1 with TileQuarry

use of buildcraft.builders.tile.TileQuarry in project BuildCraft by BuildCraft.

the class BlockQuarry method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TileQuarry) {
        for (BlockPos blockPos : ((TileQuarry) tile).framePoses) {
            if (world.getBlockState(blockPos).getBlock() == BCBuildersBlocks.frame) {
                world.setBlockToAir(blockPos);
            }
        }
    }
    super.breakBlock(world, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) TileQuarry(buildcraft.builders.tile.TileQuarry)

Example 2 with TileQuarry

use of buildcraft.builders.tile.TileQuarry in project BuildCraft by BuildCraft.

the class AdvDebuggerQuarry method render.

@Override
public void render(EntityPlayer player, float partialTicks) {
    TileQuarry tile = tileReference.get();
    if (tile == null || !tile.frameBox.isInitialized()) {
        return;
    }
    List<ChunkPos> chunkPoses = new ArrayList<>(ChunkLoaderManager.getChunksToLoad(tile));
    chunkPoses.sort(Comparator.comparingDouble(chunkPos -> -player.getPositionEyes(partialTicks).distanceTo(new Vec3d(chunkPos.getXStart() + 0.5 + (chunkPos.getXEnd() - chunkPos.getXStart()) / 2, player.getPositionEyes(partialTicks).y, chunkPos.getZStart() + 0.5 + (chunkPos.getZEnd() - chunkPos.getZStart()) / 2))));
    GlStateManager.enableBlend();
    BufferBuilder bb = Tessellator.getInstance().getBuffer();
    bb.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    for (ChunkPos chunkPos : chunkPoses) {
        DebugRenderHelper.renderAABB(bb, new AxisAlignedBB(chunkPos.getXStart() + 0.5D, tile.frameBox.min().getY() + 0.5D, chunkPos.getZStart() + 0.5D, chunkPos.getXEnd() + 0.5D, tile.frameBox.max().getY() + 0.5D, chunkPos.getZEnd() + 0.5D), COLOUR_CHUNK);
    }
    Tessellator.getInstance().draw();
    GlStateManager.disableBlend();
}
Also used : DebugRenderHelper(buildcraft.lib.debug.DebugRenderHelper) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) GlStateManager(net.minecraft.client.renderer.GlStateManager) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ChunkPos(net.minecraft.util.math.ChunkPos) ChunkLoaderManager(buildcraft.lib.chunkload.ChunkLoaderManager) DetachedRenderer(buildcraft.lib.client.render.DetachedRenderer) ArrayList(java.util.ArrayList) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) List(java.util.List) Tessellator(net.minecraft.client.renderer.Tessellator) Vec3d(net.minecraft.util.math.Vec3d) TileQuarry(buildcraft.builders.tile.TileQuarry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) GL11(org.lwjgl.opengl.GL11) WeakReference(java.lang.ref.WeakReference) Comparator(java.util.Comparator) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ArrayList(java.util.ArrayList) ChunkPos(net.minecraft.util.math.ChunkPos) TileQuarry(buildcraft.builders.tile.TileQuarry) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with TileQuarry

use of buildcraft.builders.tile.TileQuarry in project BuildCraft by BuildCraft.

the class RenderQuarry method render.

@Override
public void render(TileQuarry tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    Profiler profiler = Minecraft.getMinecraft().mcProfiler;
    profiler.startSection("bc");
    profiler.startSection("quarry");
    profiler.startSection("setup");
    SpriteUtil.bindBlockTextureMap();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.enableBlend();
    GlStateManager.enableCull();
    if (Minecraft.isAmbientOcclusionEnabled()) {
        GlStateManager.shadeModel(GL11.GL_SMOOTH);
    } else {
        GlStateManager.shadeModel(GL11.GL_FLAT);
    }
    GlStateManager.pushMatrix();
    GlStateManager.translate(x - tile.getPos().getX(), y - tile.getPos().getY(), z - tile.getPos().getZ());
    final BlockPos min = tile.frameBox.min();
    final BlockPos max = tile.frameBox.max();
    profiler.endSection();
    if (tile.frameBox.isInitialized()) {
        double yOffset = 1 + 4 / 16D;
        profiler.startSection("laser");
        if (tile.currentTask != null && tile.currentTask instanceof TileQuarry.TaskBreakBlock) {
            TileQuarry.TaskBreakBlock taskBreakBlock = (TileQuarry.TaskBreakBlock) tile.currentTask;
            BlockPos pos = taskBreakBlock.breakPos;
            if (tile.drillPos == null) {
                if (taskBreakBlock.clientPower != 0) {
                    // Don't render a laser before we have any power
                    Vec3d from = VecUtil.convertCenter(tile.getPos());
                    Vec3d to = VecUtil.convertCenter(pos);
                    LaserData_BC8 laser = new LaserData_BC8(LASER, from, to, 1 / 16.0);
                    LaserRenderer_BC8.renderLaserStatic(laser);
                }
            } else {
                long power = (long) (taskBreakBlock.prevClientPower + (taskBreakBlock.clientPower - taskBreakBlock.prevClientPower) * (double) partialTicks);
                AxisAlignedBB aabb = tile.getWorld().getBlockState(pos).getBoundingBox(tile.getWorld(), pos);
                double value = (double) power / taskBreakBlock.getTarget();
                if (value < 0.9) {
                    value = 1 - value / 0.9;
                } else {
                    value = (value - 0.9) / 0.1;
                }
                double scaleMin = 1 - (1 - aabb.maxY) - (aabb.maxY - aabb.minY) / 2;
                double scaleMax = 1 + 4 / 16D;
                yOffset = scaleMin + value * (scaleMax - scaleMin);
            }
        }
        profiler.endStartSection("frame");
        if (tile.clientDrillPos != null && tile.prevClientDrillPos != null) {
            Vec3d interpolatedPos = tile.prevClientDrillPos.add(tile.clientDrillPos.subtract(tile.prevClientDrillPos).scale(partialTicks));
            LaserRenderer_BC8.renderLaserStatic(new // 
            LaserData_BC8(// 
            FRAME, // 
            new Vec3d(interpolatedPos.x + 0.5, max.getY() + 0.5, interpolatedPos.z), // 
            new Vec3d(interpolatedPos.x + 0.5, max.getY() + 0.5, max.getZ() + 12 / 16D), 1 / 16D, true, true, 0));
            LaserRenderer_BC8.renderLaserStatic(new // 
            LaserData_BC8(// 
            FRAME, // 
            new Vec3d(interpolatedPos.x + 0.5, max.getY() + 0.5, interpolatedPos.z), // 
            new Vec3d(interpolatedPos.x + 0.5, max.getY() + 0.5, min.getZ() + 4 / 16D), 1 / 16D, true, true, 0));
            LaserRenderer_BC8.renderLaserStatic(new // 
            LaserData_BC8(// 
            FRAME, // 
            new Vec3d(interpolatedPos.x, max.getY() + 0.5, interpolatedPos.z + 0.5), // 
            new Vec3d(max.getX() + 12 / 16D, max.getY() + 0.5, interpolatedPos.z + 0.5), 1 / 16D, true, true, 0));
            LaserRenderer_BC8.renderLaserStatic(new // 
            LaserData_BC8(// 
            FRAME, // 
            new Vec3d(interpolatedPos.x, max.getY() + 0.5, interpolatedPos.z + 0.5), // 
            new Vec3d(min.getX() + 4 / 16D, max.getY() + 0.5, interpolatedPos.z + 0.5), 1 / 16D, true, true, 0));
            LaserRenderer_BC8.renderLaserStatic(new // 
            LaserData_BC8(// 
            FRAME_BOTTOM, // 
            new Vec3d(interpolatedPos.x + 0.5, interpolatedPos.y + 1 + 4 / 16D, interpolatedPos.z + 0.5), // 
            new Vec3d(interpolatedPos.x + 0.5, max.getY() + 0.5, interpolatedPos.z + 0.5), 1 / 16D, true, true, 0));
            LaserRenderer_BC8.renderLaserStatic(new // 
            LaserData_BC8(// 
            DRILL, // 
            new Vec3d(interpolatedPos.x + 0.5, interpolatedPos.y + 1 + yOffset, interpolatedPos.z + 0.5), // 
            new Vec3d(interpolatedPos.x + 0.5, interpolatedPos.y + yOffset, interpolatedPos.z + 0.5), 1 / 16D, true, true, 0));
        } else {
            LaserBoxRenderer.renderLaserBoxStatic(tile.frameBox, BuildCraftLaserManager.STRIPES_WRITE, true);
        }
        profiler.endSection();
    }
    GlStateManager.popMatrix();
    profiler.startSection("items");
    if (tile.frameBox.isInitialized() && false) {
        TileQuarry.TaskAddFrame currentTask = (TileQuarry.TaskAddFrame) tile.currentTask;
        int index = tile.framePoses.indexOf(currentTask.framePos);
        if (index > 1) {
            double progress = (double) currentTask.power / currentTask.getTarget() * (index - 1) / tile.framePoses.size();
            double progress1 = // 
            (progress >= 0 && progress <= 0.25) ? // 
            progress * 4 : // 
            (progress >= 0.25 && progress <= 0.5) ? // 
            1 : // 
            (progress >= 0.5 && progress <= 0.75) ? // 
            1 - (progress - 0.5) * 4 : (progress >= 0.75 && progress <= 1) ? 0 : -1;
            double progress2 = (progress >= 0 && progress <= 0.25) ? 1 : (progress >= 0.25 && progress <= 0.5) ? 1 - (progress - 0.25) * 4 : (progress >= 0.5 && progress <= 0.75) ? 0 : (progress >= 0.75 && progress <= 1) ? (progress - 0.75) * 4 : -1;
            double xProgress = -1;
            double zProgress = -1;
            EnumFacing side = tile.getWorld().getBlockState(tile.getPos()).getValue(BuildCraftProperties.BLOCK_FACING).getOpposite();
            BlockPos firstPos = tile.getPos().offset(side);
            switch(side) {
                case SOUTH:
                    if (firstPos.getX() == min.getX()) {
                        xProgress = 1 - progress2;
                        zProgress = progress1;
                    } else {
                        xProgress = progress2;
                        zProgress = progress1;
                    }
                    break;
                case WEST:
                    if (firstPos.getZ() == min.getZ()) {
                        xProgress = 1 - progress1;
                        zProgress = 1 - progress2;
                    } else {
                        xProgress = 1 - progress1;
                        zProgress = progress2;
                    }
                    break;
                case NORTH:
                    if (firstPos.getX() == min.getX()) {
                        xProgress = 1 - progress2;
                        zProgress = 1 - progress1;
                    } else {
                        xProgress = progress2;
                        zProgress = 1 - progress1;
                    }
                    break;
                case EAST:
                    if (firstPos.getZ() == min.getZ()) {
                        xProgress = progress1;
                        zProgress = 1 - progress2;
                    } else {
                        xProgress = progress1;
                        zProgress = progress2;
                    }
                    break;
            }
            double xResult = min.getX() + (max.getX() - min.getX()) * xProgress;
            double zResult = min.getZ() + (max.getZ() - min.getZ()) * zProgress;
            ItemStack stack = new ItemStack(BCBuildersBlocks.frame);
            RenderHelper.disableStandardItemLighting();
            GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
            GlStateManager.disableTexture2D();
            GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
            GlStateManager.pushMatrix();
            GlStateManager.translate(x - tile.getPos().getX(), y - tile.getPos().getY(), z - tile.getPos().getZ());
            GlStateManager.pushMatrix();
            GlStateManager.translate(xResult + 0.5, tile.getPos().getY(), zResult + 0.5);
            GlStateManager.scale(3, 3, 3);
            Minecraft.getMinecraft().getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.GROUND);
            GlStateManager.popMatrix();
            GlStateManager.popMatrix();
        }
    }
    RenderHelper.enableStandardItemLighting();
    profiler.endSection();
    profiler.endSection();
    profiler.endSection();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumFacing(net.minecraft.util.EnumFacing) LaserData_BC8(buildcraft.lib.client.render.laser.LaserData_BC8) Vec3d(net.minecraft.util.math.Vec3d) Profiler(net.minecraft.profiler.Profiler) BlockPos(net.minecraft.util.math.BlockPos) TileQuarry(buildcraft.builders.tile.TileQuarry) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TileQuarry (buildcraft.builders.tile.TileQuarry)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3d (net.minecraft.util.math.Vec3d)2 ChunkLoaderManager (buildcraft.lib.chunkload.ChunkLoaderManager)1 DetachedRenderer (buildcraft.lib.client.render.DetachedRenderer)1 LaserData_BC8 (buildcraft.lib.client.render.laser.LaserData_BC8)1 DebugRenderHelper (buildcraft.lib.debug.DebugRenderHelper)1 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 GlStateManager (net.minecraft.client.renderer.GlStateManager)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 DefaultVertexFormats (net.minecraft.client.renderer.vertex.DefaultVertexFormats)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 Profiler (net.minecraft.profiler.Profiler)1 TileEntity (net.minecraft.tileentity.TileEntity)1