From 140f14aab55024a6e3134830d599dfc886bd1f1e Mon Sep 17 00:00:00 2001 From: Adrian Date: Sun, 19 Jul 2015 15:36:45 +0200 Subject: [PATCH] fix #2892 and zone planner mouse weirdness --- buildcraft_resources/changelog/7.0.17 | 5 +++ .../robotics/gui/ContainerZonePlan.java | 35 ++++++++++++------- .../buildcraft/robotics/gui/GuiZonePlan.java | 23 ++++++------ 3 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 buildcraft_resources/changelog/7.0.17 diff --git a/buildcraft_resources/changelog/7.0.17 b/buildcraft_resources/changelog/7.0.17 new file mode 100644 index 00000000..bffa2d71 --- /dev/null +++ b/buildcraft_resources/changelog/7.0.17 @@ -0,0 +1,5 @@ +Bugs fixed: + +* [#2892] Disconnect on large-resolution Zone Planner fullscreen (asie) +* [#2891] Boxes ignoring the south and east boundaries when rounding (hea3ven) +* Accidentally setting an area in the Zone Planner GUI upon pressing fullscreen (asie) diff --git a/common/buildcraft/robotics/gui/ContainerZonePlan.java b/common/buildcraft/robotics/gui/ContainerZonePlan.java index f62afb2f..ce050cef 100755 --- a/common/buildcraft/robotics/gui/ContainerZonePlan.java +++ b/common/buildcraft/robotics/gui/ContainerZonePlan.java @@ -27,8 +27,10 @@ import buildcraft.core.lib.network.command.PacketCommand; import buildcraft.core.lib.render.DynamicTextureBC; import buildcraft.core.lib.utils.NetworkUtils; import buildcraft.robotics.TileZonePlan; +import buildcraft.robotics.map.MapWorld; public class ContainerZonePlan extends BuildCraftContainer implements ICommandReceiver { + private static final int MAX_PACKET_LENGTH = 30000; public DynamicTextureBC mapTexture; public ZonePlan currentAreaSelection; @@ -92,9 +94,10 @@ public class ContainerZonePlan extends BuildCraftContainer implements ICommandRe gui.refreshSelectedArea(); } else if ("receiveImage".equals(command)) { int size = stream.readUnsignedMedium(); + int pos = stream.readUnsignedMedium(); - for (int i = 0; i < size; ++i) { - mapTexture.colorMap[i] = 0xFF000000 | MapColor.mapColorArray[stream.readUnsignedByte()].colorValue; + for (int i = 0; i < Math.min(size - pos, MAX_PACKET_LENGTH); ++i) { + mapTexture.colorMap[pos + i] = 0xFF000000 | MapColor.mapColorArray[stream.readUnsignedByte()].colorValue; } } } else if (side.isServer()) { @@ -123,28 +126,36 @@ public class ContainerZonePlan extends BuildCraftContainer implements ICommandRe private void computeMap(int cx, int cz, int width, int height, int blocksPerPixel, EntityPlayer player) { final byte[] textureData = new byte[width * height]; + MapWorld w = BuildCraftRobotics.manager.getWorld(map.getWorldObj()); int startX = cx - width * blocksPerPixel / 2; int startZ = cz - height * blocksPerPixel / 2; + int mapStartX = (map.chunkStartX << 4); + int mapStartZ = (map.chunkStartZ << 4); for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { int x = startX + i * blocksPerPixel; int z = startZ + j * blocksPerPixel; - int ix = x - (map.chunkStartX << 4); - int iz = z - (map.chunkStartZ << 4); + int ix = x - mapStartX; + int iz = z - mapStartZ; if (ix >= 0 && iz >= 0 && ix < TileZonePlan.RESOLUTION && iz < TileZonePlan.RESOLUTION) { - textureData[i + j * width] = (byte) BuildCraftRobotics.manager.getWorld(map.getWorldObj()) - .getColor(x, z); + textureData[i + j * width] = (byte) w.getColor(x, z); } } } - BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "receiveImage", new CommandWriter() { - public void write(ByteBuf data) { - data.writeMedium(textureData.length); - data.writeBytes(textureData); - } - })); + final int len = MAX_PACKET_LENGTH; + + for (int i = 0; i < textureData.length; i += len) { + final int pos = i; + BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "receiveImage", new CommandWriter() { + public void write(ByteBuf data) { + data.writeMedium(textureData.length); + data.writeMedium(pos); + data.writeBytes(textureData, pos, Math.min(textureData.length - pos, len)); + } + })); + } } } diff --git a/common/buildcraft/robotics/gui/GuiZonePlan.java b/common/buildcraft/robotics/gui/GuiZonePlan.java index c6ae18a0..e68d2c92 100755 --- a/common/buildcraft/robotics/gui/GuiZonePlan.java +++ b/common/buildcraft/robotics/gui/GuiZonePlan.java @@ -234,10 +234,6 @@ public class GuiZonePlan extends GuiAdvancedInterface { @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { - super.mouseClicked(mouseX, mouseY, mouseButton); - - textField.mouseClicked(mouseX - guiLeft, mouseY - guiTop, mouseButton); - int blocksX = (mouseX - mapXMin) * zoomLevel; int blocksZ = (mouseY - mapYMin) * zoomLevel; @@ -255,22 +251,27 @@ public class GuiZonePlan extends GuiAdvancedInterface { uploadMap(); refreshSelectedArea(); + return; } else { inSelection = true; selX1 = mouseX; selY1 = mouseY; selX2 = 0; selY2 = 0; + return; } - } else { - AdvancedSlot slot = getSlotAtLocation(mouseX, mouseY); + } - if (slot instanceof AreaSlot) { - colorSelected = (AreaSlot) slot; + super.mouseClicked(mouseX, mouseY, mouseButton); + textField.mouseClicked(mouseX - guiLeft, mouseY - guiTop, mouseButton); - newSelection.setColor(0, 0, colorSelected.color.getDarkHex(), alpha); - getContainer().loadArea(colorSelected.color.ordinal()); - } + AdvancedSlot slot = getSlotAtLocation(mouseX, mouseY); + + if (slot instanceof AreaSlot) { + colorSelected = (AreaSlot) slot; + + newSelection.setColor(0, 0, colorSelected.color.getDarkHex(), alpha); + getContainer().loadArea(colorSelected.color.ordinal()); } }