Search in sources :

Example 6 with ZonePlan

use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.

the class TileZonePlanner method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    for (int i = 0; i < layers.length; i++) {
        ZonePlan layer = layers[i];
        layer.readFromNBT(nbt.getCompoundTag("layer_" + i));
    }
}
Also used : ZonePlan(buildcraft.robotics.zone.ZonePlan)

Example 7 with ZonePlan

use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.

the class TileZonePlanner method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);
    for (int i = 0; i < layers.length; i++) {
        ZonePlan layer = layers[i];
        NBTTagCompound layerCompound = new NBTTagCompound();
        layer.writeToNBT(layerCompound);
        nbt.setTag("layer_" + i, layerCompound);
    }
    return nbt;
}
Also used : ZonePlan(buildcraft.robotics.zone.ZonePlan) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 8 with ZonePlan

use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.

the class TileZonePlanner method update.

@Override
public void update() {
    deltaManager.tick();
    if (getWorld().isRemote) {
        return;
    }
    {
        // noinspection ConstantConditions
        if (!invInputPaintbrush.getStackInSlot(0).isEmpty() && invInputPaintbrush.getStackInSlot(0).getItem() instanceof ItemPaintbrush_BC8 && !invInputMapLocation.getStackInSlot(0).isEmpty() && invInputMapLocation.getStackInSlot(0).getItem() instanceof ItemMapLocation && invInputMapLocation.getStackInSlot(0).getTagCompound() != null && invInputMapLocation.getStackInSlot(0).getTagCompound().hasKey("chunkMapping") && invInputResult.getStackInSlot(0).isEmpty()) {
            if (progressInput == 0) {
                deltaProgressInput.addDelta(0, 200, 1);
                deltaProgressInput.addDelta(200, 205, -1);
            }
            if (progressInput < 200) {
                progressInput++;
                return;
            }
            ZonePlan zonePlan = new ZonePlan();
            zonePlan.readFromNBT(invInputMapLocation.getStackInSlot(0).getTagCompound());
            layers[BCCoreItems.paintbrush.getBrushFromStack(invInputPaintbrush.getStackInSlot(0)).colour.getMetadata()] = zonePlan.getWithOffset(-pos.getX(), -pos.getZ());
            invInputMapLocation.setStackInSlot(0, StackUtil.EMPTY);
            invInputResult.setStackInSlot(0, new ItemStack(BCCoreItems.mapLocation));
            this.markDirty();
            this.sendNetworkUpdate(NET_RENDER_DATA);
            progressInput = 0;
        } else if (progressInput != -1) {
            progressInput = -1;
            deltaProgressInput.setValue(0);
        }
    }
    {
        if (!invOutputPaintbrush.getStackInSlot(0).isEmpty() && invOutputPaintbrush.getStackInSlot(0).getItem() instanceof ItemPaintbrush_BC8 && !invOutputMapLocation.getStackInSlot(0).isEmpty() && invOutputMapLocation.getStackInSlot(0).getItem() instanceof ItemMapLocation && invOutputResult.getStackInSlot(0).isEmpty()) {
            if (progressOutput == 0) {
                deltaProgressOutput.addDelta(0, 200, 1);
                deltaProgressOutput.addDelta(200, 205, -1);
            }
            if (progressOutput < 200) {
                progressOutput++;
                return;
            }
            ItemMapLocation.setZone(invOutputMapLocation.getStackInSlot(0), layers[BCCoreItems.paintbrush.getBrushFromStack(invOutputPaintbrush.getStackInSlot(0)).colour.getMetadata()].getWithOffset(pos.getX(), pos.getZ()));
            invOutputResult.setStackInSlot(0, invOutputMapLocation.getStackInSlot(0));
            invOutputMapLocation.setStackInSlot(0, StackUtil.EMPTY);
            progressOutput = 0;
        } else if (progressOutput != -1) {
            progressOutput = -1;
            deltaProgressOutput.setValue(0);
        }
    }
}
Also used : ZonePlan(buildcraft.robotics.zone.ZonePlan) ItemMapLocation(buildcraft.core.item.ItemMapLocation) ItemPaintbrush_BC8(buildcraft.core.item.ItemPaintbrush_BC8) ItemStack(net.minecraft.item.ItemStack)

Example 9 with ZonePlan

use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.

the class TileZonePlanner method readPayload.

@Override
public void readPayload(int id, PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
    super.readPayload(id, buffer, side, ctx);
    if (side == Side.CLIENT) {
        if (id == NET_RENDER_DATA) {
            for (int i = 0; i < layers.length; i++) {
                ZonePlan layer = layers[i];
                layers[i] = layer.readFromByteBuf(buffer);
            }
        }
    } else if (side == Side.SERVER) {
        if (id == NET_PLAN_CHANGE) {
            int index = buffer.readUnsignedShort();
            layers[index].readFromByteBuf(buffer);
            markDirty();
            sendNetworkUpdate(NET_RENDER_DATA);
        }
    }
}
Also used : ZonePlan(buildcraft.robotics.zone.ZonePlan)

Example 10 with ZonePlan

use of buildcraft.robotics.zone.ZonePlan in project BuildCraft by BuildCraft.

the class GuiZonePlanner method drawForegroundLayer.

@SuppressWarnings("PointlessBitwiseExpression")
@Override
protected void drawForegroundLayer() {
    camY += scaleSpeed;
    scaleSpeed *= 0.7F;
    int posX = (int) positionX;
    int posZ = (int) positionZ;
    int dimension = mc.world.provider.getDimension();
    {
        ChunkPos chunkPos = new ChunkPos(posX >> 4, posZ >> 4);
        ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
        BlockPos pos = null;
        if (zonePlannerMapChunk != null) {
            MapColourData data = zonePlannerMapChunk.getData(posX, posZ);
            if (data != null) {
                pos = new BlockPos(posX, data.posY, posZ);
            }
        }
        if (pos != null && pos.getY() + 10 > camY) {
            camY = Math.max(camY, pos.getY() + 10);
        }
    }
    int x = guiLeft;
    int y = guiTop;
    if (lastSelected != null) {
        String text = "X: " + lastSelected.getX() + " Y: " + lastSelected.getY() + " Z: " + lastSelected.getZ();
        fontRenderer.drawString(text, x + 130, y + 130, 0x404040);
    }
    int offsetX = 8;
    int offsetY = 9;
    int sizeX = 213;
    int sizeY = 100;
    GlStateManager.pushMatrix();
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.pushMatrix();
    GlStateManager.loadIdentity();
    ScaledResolution scaledResolution = new ScaledResolution(mc);
    int viewportX = (x + offsetX) * scaledResolution.getScaleFactor();
    int viewportY = mc.displayHeight - (sizeY + y + offsetY) * scaledResolution.getScaleFactor();
    int viewportWidth = sizeX * scaledResolution.getScaleFactor();
    int viewportHeight = sizeY * scaledResolution.getScaleFactor();
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glScissor(viewportX, viewportY, viewportWidth, viewportHeight);
    GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    GlStateManager.viewport(viewportX, viewportY, viewportWidth, viewportHeight);
    GlStateManager.scale(scaledResolution.getScaleFactor(), scaledResolution.getScaleFactor(), 1);
    GLU.gluPerspective(70.0F, (float) sizeX / sizeY, 1F, 10000.0F);
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.loadIdentity();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.enableRescaleNormal();
    // look down
    GlStateManager.rotate(90, 1, 0, 0);
    GlStateManager.pushMatrix();
    GlStateManager.translate(-positionX, -camY, -positionZ);
    GlStateManager.disableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.disableTexture2D();
    int minScreenX = (x + offsetX) * scaledResolution.getScaleFactor();
    int minScreenY = (scaledResolution.getScaledHeight() - (y + offsetY)) * scaledResolution.getScaleFactor();
    int maxScreenX = (x + offsetX + sizeX) * scaledResolution.getScaleFactor();
    int maxScreenY = (scaledResolution.getScaledHeight() - (y + offsetY + sizeY)) * scaledResolution.getScaleFactor();
    int minChunkX = (posX >> 4) - 8;
    int minChunkZ = (posZ >> 4) - 8;
    int maxChunkX = (posX >> 4) + 8;
    int maxChunkZ = (posZ >> 4) + 8;
    // noinspection SuspiciousNameCombination
    List<ChunkPos> chunkPosBounds = Stream.of(Pair.of(minScreenX, minScreenY), Pair.of(minScreenX, maxScreenY), Pair.of(maxScreenX, minScreenY), Pair.of(maxScreenX, maxScreenY)).map(p -> rayTrace(p.getLeft(), p.getRight())).filter(Objects::nonNull).map(ChunkPos::new).collect(Collectors.toList());
    for (ChunkPos chunkPos : chunkPosBounds) {
        if (chunkPos.x < minChunkX) {
            minChunkX = chunkPos.x;
        }
        if (chunkPos.z < minChunkZ) {
            minChunkZ = chunkPos.z;
        }
        if (chunkPos.x > maxChunkX) {
            maxChunkX = chunkPos.x;
        }
        if (chunkPos.z > maxChunkZ) {
            maxChunkZ = chunkPos.z;
        }
    }
    minChunkX--;
    minChunkZ--;
    maxChunkX++;
    maxChunkZ++;
    for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
        for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
            ZonePlannerMapRenderer.INSTANCE.getChunkGlList(new ZonePlannerMapChunkKey(new ChunkPos(chunkX, chunkZ), dimension, container.tile.getLevel())).ifPresent(GlStateManager::callList);
        }
    }
    BlockPos found = null;
    int foundColor = 0;
    if (Mouse.getX() >= minScreenX && Mouse.getY() <= minScreenY && Mouse.getX() <= maxScreenX && Mouse.getY() >= maxScreenY) {
        found = rayTrace(Mouse.getX(), Mouse.getY());
    }
    if (found != null) {
        ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(new ChunkPos(found), mc.world.provider.getDimension(), container.tile.getLevel()));
        if (zonePlannerMapChunk != null) {
            MapColourData data = zonePlannerMapChunk.getData(found.getX(), found.getZ());
            if (data != null) {
                foundColor = data.colour;
            }
        }
    }
    if (found != null) {
        GlStateManager.disableDepth();
        GlStateManager.enableBlend();
        GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
        GlStateManager.glLineWidth(2);
        int r = (int) (((foundColor >> 16) & 0xFF) * 0.7);
        int g = (int) (((foundColor >> 8) & 0xFF) * 0.7);
        int b = (int) (((foundColor >> 0) & 0xFF) * 0.7);
        int a = 0x77;
        ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
        BufferBuilder builder = Tessellator.getInstance().getBuffer();
        builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
        ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(builder, found.getX(), found.getY(), found.getZ());
        Tessellator.getInstance().draw();
        GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
        GlStateManager.disableBlend();
        GlStateManager.enableDepth();
    }
    GlStateManager.disableLighting();
    GlStateManager.enableBlend();
    for (int i = 0; i < container.tile.layers.length; i++) {
        if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() != i) {
            continue;
        }
        ZonePlan layer = container.tile.layers[i];
        if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() == i && bufferLayer != null) {
            layer = bufferLayer;
        }
        if (!layer.getChunkPoses().isEmpty()) {
            Tessellator.getInstance().getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
                for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
                    ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ);
                    for (int blockX = chunkPos.getXStart(); blockX <= chunkPos.getXEnd(); blockX++) {
                        for (int blockZ = chunkPos.getZStart(); blockZ <= chunkPos.getZEnd(); blockZ++) {
                            if (!layer.get(blockX - container.tile.getPos().getX(), blockZ - container.tile.getPos().getZ())) {
                                continue;
                            }
                            int height;
                            ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
                            if (zonePlannerMapChunk != null) {
                                MapColourData data = zonePlannerMapChunk.getData(blockX, blockZ);
                                if (data != null) {
                                    height = data.posY;
                                } else {
                                    continue;
                                }
                            } else {
                                continue;
                            }
                            int color = EnumDyeColor.byMetadata(i).getColorValue();
                            int r = (color >> 16) & 0xFF;
                            int g = (color >> 8) & 0xFF;
                            int b = (color >> 0) & 0xFF;
                            int a = 0x55;
                            ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
                            ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(Tessellator.getInstance().getBuffer(), blockX, height + 0.1, blockZ, height, 0.6);
                        }
                    }
                }
            }
            Tessellator.getInstance().draw();
        }
    }
    GlStateManager.disableBlend();
    GlStateManager.disableLighting();
    GlStateManager.enableTexture2D();
    lastSelected = found;
    GlStateManager.popMatrix();
    GlStateManager.disableRescaleNormal();
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.viewport(0, 0, mc.displayWidth, mc.displayHeight);
    GlStateManager.popMatrix();
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.popMatrix();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.disableBlend();
}
Also used : ItemPaintbrush_BC8(buildcraft.core.item.ItemPaintbrush_BC8) FloatBuffer(java.nio.FloatBuffer) ZonePlannerMapChunkKey(buildcraft.robotics.zone.ZonePlannerMapChunkKey) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Vector3d(javax.vecmath.Vector3d) GuiIcon(buildcraft.lib.gui.GuiIcon) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) GuiBC8(buildcraft.lib.gui.GuiBC8) BCCoreItems(buildcraft.core.BCCoreItems) Pair(org.apache.commons.lang3.tuple.Pair) IntBuffer(java.nio.IntBuffer) RenderHelper(net.minecraft.client.renderer.RenderHelper) GL11(org.lwjgl.opengl.GL11) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ZonePlan(buildcraft.robotics.zone.ZonePlan) GLU(org.lwjgl.util.glu.GLU) ZonePlannerMapChunk(buildcraft.robotics.zone.ZonePlannerMapChunk) ScaledResolution(net.minecraft.client.gui.ScaledResolution) GlStateManager(net.minecraft.client.renderer.GlStateManager) ContainerZonePlanner(buildcraft.robotics.container.ContainerZonePlanner) ZonePlannerMapRenderer(buildcraft.robotics.zone.ZonePlannerMapRenderer) ChunkPos(net.minecraft.util.math.ChunkPos) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) Mouse(org.lwjgl.input.Mouse) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BufferUtils(org.lwjgl.BufferUtils) List(java.util.List) Stream(java.util.stream.Stream) EnumDyeColor(net.minecraft.item.EnumDyeColor) Tessellator(net.minecraft.client.renderer.Tessellator) ResourceLocation(net.minecraft.util.ResourceLocation) MapColourData(buildcraft.robotics.zone.ZonePlannerMapChunk.MapColourData) ZonePlannerMapDataClient(buildcraft.robotics.zone.ZonePlannerMapDataClient) ZonePlannerMapChunkKey(buildcraft.robotics.zone.ZonePlannerMapChunkKey) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ZonePlannerMapChunk(buildcraft.robotics.zone.ZonePlannerMapChunk) GlStateManager(net.minecraft.client.renderer.GlStateManager) ScaledResolution(net.minecraft.client.gui.ScaledResolution) ZonePlan(buildcraft.robotics.zone.ZonePlan) Objects(java.util.Objects) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) MapColourData(buildcraft.robotics.zone.ZonePlannerMapChunk.MapColourData)

Aggregations

ZonePlan (buildcraft.robotics.zone.ZonePlan)10 ItemPaintbrush_BC8 (buildcraft.core.item.ItemPaintbrush_BC8)2 CommandWriter (buildcraft.core.lib.network.command.CommandWriter)2 PacketCommand (buildcraft.core.lib.network.command.PacketCommand)2 ContainerZonePlan (buildcraft.robotics.gui.ContainerZonePlan)2 ByteBuf (io.netty.buffer.ByteBuf)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 IZone (buildcraft.api.core.IZone)1 IMapLocation (buildcraft.api.items.IMapLocation)1 BCCoreItems (buildcraft.core.BCCoreItems)1 ItemMapLocation (buildcraft.core.item.ItemMapLocation)1 Packet (buildcraft.core.lib.network.base.Packet)1 GuiBC8 (buildcraft.lib.gui.GuiBC8)1 GuiIcon (buildcraft.lib.gui.GuiIcon)1 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)1 TileZonePlan (buildcraft.robotics.TileZonePlan)1 ContainerZonePlanner (buildcraft.robotics.container.ContainerZonePlanner)1 ZonePlannerMapChunk (buildcraft.robotics.zone.ZonePlannerMapChunk)1 MapColourData (buildcraft.robotics.zone.ZonePlannerMapChunk.MapColourData)1