added multi-area selection capabilities
This commit is contained in:
parent
c960176f57
commit
b117a23c5d
14 changed files with 453 additions and 83 deletions
|
@ -11,8 +11,13 @@ package buildcraft.api.core;
|
|||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public enum EnumColor {
|
||||
|
||||
BLACK,
|
||||
|
@ -101,6 +106,9 @@ public enum EnumColor {
|
|||
0xEA7835,
|
||||
0xe4e4e4};
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static IIcon brushIcons[] = new IIcon[16];
|
||||
|
||||
public int getDarkHex() {
|
||||
return DARK_HEX[ordinal()];
|
||||
}
|
||||
|
@ -182,4 +190,17 @@ public enum EnumColor {
|
|||
}
|
||||
return b.toString().trim();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void registerIcons(IIconRegister iconRegister) {
|
||||
for (EnumColor c : values()) {
|
||||
brushIcons[c.ordinal()] = iconRegister.registerIcon("buildcraft:triggers/color_"
|
||||
+ c.name().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon() {
|
||||
return brushIcons [ordinal()];
|
||||
}
|
||||
}
|
||||
|
|
BIN
buildcraft_resources/assets/buildcraft/textures/gui/map_gui.png
Executable file
BIN
buildcraft_resources/assets/buildcraft/textures/gui/map_gui.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -62,6 +62,7 @@ import buildcraft.api.boards.RedstoneBoardRobot;
|
|||
import buildcraft.api.core.BCLog;
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.api.core.EnumColor;
|
||||
import buildcraft.api.core.IIconProvider;
|
||||
import buildcraft.api.core.JavaTools;
|
||||
import buildcraft.api.gates.IAction;
|
||||
|
@ -393,6 +394,7 @@ public class BuildCraftCore extends BuildCraftMod {
|
|||
iconProvider = new CoreIconProvider();
|
||||
iconProvider.registerIcons(event.map);
|
||||
StatementIconProvider.INSTANCE.registerIcons(event.map);
|
||||
EnumColor.registerIcons(event.map);
|
||||
} else if (event.map.getTextureType() == 0) {
|
||||
BuildCraftCore.redLaserTexture = event.map.registerIcon("buildcraft:blockRedLaser");
|
||||
BuildCraftCore.blueLaserTexture = event.map.registerIcon("buildcraft:blockBlueLaser");
|
||||
|
|
|
@ -130,7 +130,7 @@ public class GuiHandler implements IGuiHandler {
|
|||
if (!(tile instanceof TileMap)) {
|
||||
return null;
|
||||
} else {
|
||||
return new ContainerMap(0);
|
||||
return new ContainerMap((TileMap) tile);
|
||||
}
|
||||
|
||||
default:
|
||||
|
|
|
@ -10,12 +10,23 @@ package buildcraft.commander;
|
|||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import buildcraft.core.MapArea;
|
||||
import buildcraft.core.gui.BuildCraftContainer;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.network.RPCMessageInfo;
|
||||
import buildcraft.core.network.RPCSide;
|
||||
|
||||
public class ContainerMap extends BuildCraftContainer {
|
||||
|
||||
public ContainerMap(int inventorySize) {
|
||||
super(inventorySize);
|
||||
private TileMap map;
|
||||
public MapArea currentAreaSelection;
|
||||
public GuiMap gui;
|
||||
|
||||
public ContainerMap(TileMap iMap) {
|
||||
super(0);
|
||||
|
||||
map = iMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,4 +34,28 @@ public class ContainerMap extends BuildCraftContainer {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void loadArea(int index) {
|
||||
RPCHandler.rpcServer(this, "rpcLoadArea", index);
|
||||
}
|
||||
|
||||
public void saveArea(int index) {
|
||||
RPCHandler.rpcServer(this, "rpcSaveArea", index, currentAreaSelection);
|
||||
}
|
||||
|
||||
@RPC(RPCSide.SERVER)
|
||||
private void rpcLoadArea(int index, RPCMessageInfo info) {
|
||||
RPCHandler.rpcPlayer(info.sender, this, "rpcAreaLoaded", map.getArea(index));
|
||||
}
|
||||
|
||||
@RPC(RPCSide.SERVER)
|
||||
private void rpcSaveArea(int index, MapArea area) {
|
||||
map.setArea(index, area);
|
||||
}
|
||||
|
||||
@RPC(RPCSide.CLIENT)
|
||||
private void rpcAreaLoaded(MapArea areaSelection) {
|
||||
currentAreaSelection = areaSelection;
|
||||
gui.refreshSelectedArea();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,22 +8,24 @@
|
|||
*/
|
||||
package buildcraft.commander;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import buildcraft.api.core.EnumColor;
|
||||
import buildcraft.core.BCDynamicTexture;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.MapArea;
|
||||
import buildcraft.core.gui.AdvancedSlot;
|
||||
import buildcraft.core.gui.GuiAdvancedInterface;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
|
||||
public class GuiMap extends GuiAdvancedInterface {
|
||||
|
||||
private static final int MAP_WIDTH = 300;
|
||||
private static final int MAP_HEIGHT = 200;
|
||||
private int mapWidth = 200;
|
||||
private int mapHeight = 100;
|
||||
|
||||
private TileMap map;
|
||||
|
||||
|
@ -34,11 +36,10 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
selY2 = 0;
|
||||
private boolean inSelection = false;
|
||||
|
||||
private MapArea areaSelection;
|
||||
private BCDynamicTexture currentSelection;
|
||||
|
||||
private static final ResourceLocation TMP_TEXTURE = new ResourceLocation("buildcraft",
|
||||
DefaultProps.TEXTURE_PATH_GUI + "/builder_blueprint.png");
|
||||
DefaultProps.TEXTURE_PATH_GUI + "/map_gui.png");
|
||||
|
||||
private int mapXMin = 0;
|
||||
private int mapYMin = 0;
|
||||
|
@ -47,24 +48,68 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
private int cx;
|
||||
private int cz;
|
||||
|
||||
private AreaSlot colorSelected = null;
|
||||
|
||||
private float alpha = 0.8F;
|
||||
|
||||
private static class AreaSlot extends AdvancedSlot {
|
||||
|
||||
public EnumColor color;
|
||||
|
||||
public AreaSlot(GuiAdvancedInterface gui, int x, int y, EnumColor iColor) {
|
||||
super(gui, x, y);
|
||||
|
||||
color = iColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon() {
|
||||
return color.getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return color.getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
public GuiMap(IInventory inventory, TileMap iMap) {
|
||||
super(new ContainerMap(0), inventory, TMP_TEXTURE);
|
||||
super(new ContainerMap(iMap), inventory, TMP_TEXTURE);
|
||||
|
||||
xSize = 256;
|
||||
ySize = 220;
|
||||
|
||||
map = iMap;
|
||||
|
||||
map.bcTexture = new BCDynamicTexture(MAP_WIDTH, MAP_HEIGHT);
|
||||
map.bcTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
map.bcTexture.createDynamicTexture();
|
||||
|
||||
currentSelection = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
currentSelection.createDynamicTexture();
|
||||
|
||||
newSelection = new BCDynamicTexture(1, 1);
|
||||
newSelection.createDynamicTexture();
|
||||
newSelection.setColor(0, 0, 1, 0, 0, 0.4F);
|
||||
|
||||
areaSelection = new MapArea();
|
||||
|
||||
getContainer().currentAreaSelection = new MapArea();
|
||||
|
||||
cx = map.xCoord;
|
||||
cz = map.zCoord;
|
||||
|
||||
slots = new AdvancedSlot[16];
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
slots[i * 4 + j] = new AreaSlot(this, 8 + 18 * i, 138 + 18 * j, EnumColor.values()[i * 4 + j]);
|
||||
}
|
||||
}
|
||||
|
||||
colorSelected = (AreaSlot) slots[0];
|
||||
|
||||
newSelection.setColor(0, 0, colorSelected.color.getDarkHex(), alpha);
|
||||
|
||||
uploadMap();
|
||||
getContainer().gui = this;
|
||||
}
|
||||
|
||||
private void uploadMap() {
|
||||
|
@ -74,14 +119,31 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
|
||||
super.drawGuiContainerBackgroundLayer(f, x, y);
|
||||
|
||||
int cornerX = (width - xSize) / 2;
|
||||
int cornerY = (height - ySize) / 2;
|
||||
|
||||
mapXMin = (width - map.bcTexture.width) / 2;
|
||||
mapYMin = (height - map.bcTexture.height) / 2;
|
||||
|
||||
if (map.bcTexture.height <= 200) {
|
||||
mapYMin = cornerY + 20;
|
||||
} else {
|
||||
mapYMin = (height - map.bcTexture.height) / 2;
|
||||
}
|
||||
|
||||
map.bcTexture.drawMap(mapXMin, mapYMin, zLevel);
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
||||
currentSelection.drawMap(mapXMin, mapYMin, zLevel);
|
||||
|
||||
GL11.glPopAttrib();
|
||||
|
||||
newSelection.updateDynamicTexture();
|
||||
|
||||
if (selX2 != 0) {
|
||||
if (inSelection && selX2 != 0) {
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
||||
|
@ -93,6 +155,13 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
drawTexturedModalRect(x1, y1, 0, 0, x2 - x1 + 1, y2 - y1 + 1);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
if (map.bcTexture.height <= 200) {
|
||||
drawBackgroundSlots();
|
||||
|
||||
bindTexture(texture);
|
||||
drawTexturedModalRect(cornerX + colorSelected.x, cornerY + colorSelected.y, 0, 220, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,42 +171,91 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
int blocksX = (mouseX - mapXMin) * zoomLevel;
|
||||
int blocksZ = (mouseY - mapYMin) * zoomLevel;
|
||||
|
||||
int blockStartX = cx - MAP_WIDTH * zoomLevel / 2;
|
||||
int blockStartZ = cz - MAP_HEIGHT * zoomLevel / 2;
|
||||
int blockStartX = cx - mapWidth * zoomLevel / 2;
|
||||
int blockStartZ = cz - mapHeight * zoomLevel / 2;
|
||||
|
||||
boolean clickOnMap = mouseX >= mapXMin
|
||||
&& mouseX <= mapXMin + map.bcTexture.width && mouseY >= mapYMin &&
|
||||
mouseY <= mapYMin + map.bcTexture.height;
|
||||
|
||||
if (clickOnMap) {
|
||||
cx = blockStartX + blocksX;
|
||||
cz = blockStartZ + blocksZ;
|
||||
uploadMap();
|
||||
}
|
||||
if (mouseButton == 1) {
|
||||
cx = blockStartX + blocksX;
|
||||
cz = blockStartZ + blocksZ;
|
||||
|
||||
/*
|
||||
* if (inSelection) { inSelection = false; } else if (mouseX >= mapXMin
|
||||
* && mouseX <= mapXMin + map.bcTexture.width && mouseY >= mapYMin &&
|
||||
* mouseY <= mapYMin + map.bcTexture.height) {
|
||||
*
|
||||
* inSelection = true; selX1 = mouseX; selY1 = mouseY; selX2 = 0; selY2
|
||||
* = 0; }
|
||||
*/
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
} else {
|
||||
inSelection = true;
|
||||
selX1 = mouseX;
|
||||
selY1 = mouseY;
|
||||
selX2 = 0;
|
||||
selY2 = 0;
|
||||
}
|
||||
} else {
|
||||
int cornerX = (width - xSize) / 2;
|
||||
int cornerY = (height - ySize) / 2;
|
||||
|
||||
int position = getSlotAtLocation(mouseX - cornerX, mouseY - cornerY);
|
||||
|
||||
AdvancedSlot slot = null;
|
||||
|
||||
if (position < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
slot = slots[position];
|
||||
|
||||
if (slot instanceof AreaSlot) {
|
||||
colorSelected = (AreaSlot) slot;
|
||||
|
||||
newSelection.setColor(0, 0, colorSelected.color.getDarkHex(), alpha);
|
||||
getContainer().loadArea(colorSelected.color.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
|
||||
int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||
int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int lastButtonBlicked, long time) {
|
||||
super.mouseClickMove(mouseX, mouseY, lastButtonBlicked, time);
|
||||
|
||||
if (inSelection
|
||||
&& x >= mapXMin && x <= mapXMin + map.bcTexture.width
|
||||
&& y >= mapYMin && y <= mapYMin + map.bcTexture.height) {
|
||||
&& mouseX >= mapXMin && mouseX <= mapXMin + map.bcTexture.width
|
||||
&& mouseY >= mapYMin && mouseY <= mapYMin + map.bcTexture.height) {
|
||||
|
||||
selX2 = x;
|
||||
selY2 = y;
|
||||
selX2 = mouseX;
|
||||
selY2 = mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int eventType) {
|
||||
super.mouseMovedOrUp(mouseX, mouseY, eventType);
|
||||
|
||||
if (eventType != -1 && inSelection) {
|
||||
int blockStartX = cx - mapWidth * zoomLevel / 2;
|
||||
int blockStartZ = cz - mapHeight * zoomLevel / 2;
|
||||
|
||||
int x1 = selX1 < selX2 ? selX1 : selX2;
|
||||
int x2 = selX1 < selX2 ? selX2 : selX1;
|
||||
int y1 = selY1 < selY2 ? selY1 : selY2;
|
||||
int y2 = selY1 < selY2 ? selY2 : selY1;
|
||||
|
||||
int lengthX = (x2 - x1) * zoomLevel;
|
||||
int lengthY = (y2 - y1) * zoomLevel;
|
||||
|
||||
for (int i = 0; i <= lengthX; ++i) {
|
||||
for (int j = 0; j <= lengthY; ++j) {
|
||||
int x = blockStartX + (x1 - mapXMin) * zoomLevel + i;
|
||||
int z = blockStartZ + (y1 - mapYMin) * zoomLevel + j;
|
||||
|
||||
getContainer().currentAreaSelection.set(x, z, true);
|
||||
}
|
||||
}
|
||||
|
||||
inSelection = false;
|
||||
getContainer().saveArea(colorSelected.color.ordinal());
|
||||
refreshSelectedArea();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,12 +263,89 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
protected void keyTyped(char carac, int val) {
|
||||
super.keyTyped(carac, val);
|
||||
|
||||
if (carac == 'z' && zoomLevel > 1) {
|
||||
if (carac == '+' && zoomLevel > 1) {
|
||||
zoomLevel--;
|
||||
uploadMap();
|
||||
} else if (carac == 'Z' && zoomLevel < 6) {
|
||||
refreshSelectedArea();
|
||||
} else if (carac == '-' && zoomLevel < 6) {
|
||||
zoomLevel++;
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
} else if (carac == 'm') {
|
||||
mapWidth = 200;
|
||||
mapHeight = 100;
|
||||
|
||||
map.bcTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
map.bcTexture.createDynamicTexture();
|
||||
|
||||
currentSelection = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
currentSelection.createDynamicTexture();
|
||||
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
} else if (carac == 'M') {
|
||||
mapWidth = this.mc.displayWidth;
|
||||
mapHeight = this.mc.displayHeight;
|
||||
|
||||
map.bcTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
map.bcTexture.createDynamicTexture();
|
||||
|
||||
currentSelection = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
currentSelection.createDynamicTexture();
|
||||
|
||||
uploadMap();
|
||||
refreshSelectedArea();
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshSelectedArea() {
|
||||
int color = colorSelected.color.getDarkHex();
|
||||
|
||||
int rAdd = (color >> 16) & 255;
|
||||
int gAdd = (color >> 8) & 255;
|
||||
int bAdd = color & 255;
|
||||
|
||||
for (int i = 0; i < currentSelection.width; ++i) {
|
||||
for (int j = 0; j < currentSelection.height; ++j) {
|
||||
int blockStartX = cx - mapWidth * zoomLevel / 2;
|
||||
int blockStartZ = cz - mapHeight * zoomLevel / 2;
|
||||
|
||||
double r = 0;
|
||||
double g = 0;
|
||||
double b = 0;
|
||||
|
||||
for (int stepi = 0; stepi < zoomLevel; ++stepi) {
|
||||
for (int stepj = 0; stepj < zoomLevel; ++stepj) {
|
||||
int x = blockStartX + i * zoomLevel + stepi;
|
||||
int z = blockStartZ + j * zoomLevel + stepj;
|
||||
|
||||
if (getContainer().currentAreaSelection.get(x, z)) {
|
||||
r += rAdd;
|
||||
g += gAdd;
|
||||
b += bAdd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r /= (zoomLevel * zoomLevel);
|
||||
g /= (zoomLevel * zoomLevel);
|
||||
b /= (zoomLevel * zoomLevel);
|
||||
|
||||
r /= 255F;
|
||||
g /= 255F;
|
||||
b /= 255F;
|
||||
|
||||
if (r != 0) {
|
||||
currentSelection.setColor(i, j, r, g, b, alpha);
|
||||
} else {
|
||||
currentSelection.setColor(i, j, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContainerMap getContainer() {
|
||||
return (ContainerMap) super.getContainer();
|
||||
}
|
||||
}
|
|
@ -8,10 +8,12 @@
|
|||
*/
|
||||
package buildcraft.commander;
|
||||
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import buildcraft.core.BCDynamicTexture;
|
||||
import buildcraft.core.MapArea;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
|
@ -20,18 +22,19 @@ import buildcraft.core.network.RPCSide;
|
|||
|
||||
public class TileMap extends TileBuildCraft {
|
||||
|
||||
private static int RESOLUTION = 1024;
|
||||
public static final int RESOLUTION = 2048;
|
||||
private static int RESOLUTION_CHUNKS = RESOLUTION >> 4;
|
||||
|
||||
public BCDynamicTexture bcTexture;
|
||||
|
||||
private int[][] colors = new int[RESOLUTION][RESOLUTION];
|
||||
private byte[] colors = new byte[RESOLUTION * RESOLUTION];
|
||||
|
||||
private boolean scan = false;
|
||||
private int chunkStartX, chunkStartZ;
|
||||
// private int curChunkX, curChunkZ;
|
||||
private int chunkIt = 0;
|
||||
|
||||
private MapArea[] selectedAreas = new MapArea[16];
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
@ -41,14 +44,6 @@ public class TileMap extends TileBuildCraft {
|
|||
if (!scan) {
|
||||
chunkIt = 0;
|
||||
scan = true;
|
||||
} else {
|
||||
if (chunkIt > RESOLUTION_CHUNKS * RESOLUTION_CHUNKS) {
|
||||
|
||||
// In this case, there's been a load problem (resolution
|
||||
// change?). just reset the scan.
|
||||
|
||||
chunkIt = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +106,7 @@ public class TileMap extends TileBuildCraft {
|
|||
|
||||
if (chunkIt > RESOLUTION_CHUNKS * RESOLUTION_CHUNKS) {
|
||||
scan = false;
|
||||
chunkIt = 0;
|
||||
} else {
|
||||
chunkIt++;
|
||||
}
|
||||
|
@ -138,7 +134,7 @@ public class TileMap extends TileBuildCraft {
|
|||
int iz = z - (chunkStartX << 4);
|
||||
|
||||
if (ix > 0 && ix < RESOLUTION && iz > 0 && iz < RESOLUTION) {
|
||||
int color = colors[ix][iz];
|
||||
int color = MapColor.mapColorArray[colors[ix + iz * RESOLUTION]].colorValue;
|
||||
|
||||
r += (color >> 16) & 255;
|
||||
g += (color >> 8) & 255;
|
||||
|
@ -200,7 +196,7 @@ public class TileMap extends TileBuildCraft {
|
|||
|
||||
for (int y = getWorld().getHeight() - 1; y >= 0; --y) {
|
||||
if (!chunk.getBlock(cx, y, cz).isAir(worldObj, x, y, z)) {
|
||||
color = chunk.getBlock(cx, y, cz).getMapColor(0).colorValue;
|
||||
color = chunk.getBlock(cx, y, cz).getMapColor(0).colorIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +204,7 @@ public class TileMap extends TileBuildCraft {
|
|||
int ix = x - chunkStartX * 16;
|
||||
int iz = z - chunkStartZ * 16;
|
||||
|
||||
colors[ix][iz] = 255 << 24 | color;
|
||||
colors[ix + iz * RESOLUTION] = (byte) color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,10 +215,7 @@ public class TileMap extends TileBuildCraft {
|
|||
|
||||
nbt.setBoolean("scan", scan);
|
||||
nbt.setInteger("chunkIt", chunkIt);
|
||||
|
||||
for (int i = 0; i < RESOLUTION; ++i) {
|
||||
nbt.setIntArray("colors[" + i + "]", colors[i]);
|
||||
}
|
||||
nbt.setByteArray("colors", colors);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -231,15 +224,24 @@ public class TileMap extends TileBuildCraft {
|
|||
|
||||
scan = nbt.getBoolean("scan");
|
||||
chunkIt = nbt.getInteger("chunkIt");
|
||||
colors = nbt.getByteArray("colors");
|
||||
|
||||
for (int i = 0; i < RESOLUTION; ++i) {
|
||||
int[] loadedArray =
|
||||
nbt.getIntArray("colors[" + i + "]");
|
||||
|
||||
if (loadedArray.length == RESOLUTION) {
|
||||
colors[i] = loadedArray;
|
||||
}
|
||||
if (colors.length != RESOLUTION * RESOLUTION || chunkIt >= colors.length) {
|
||||
colors = new byte[RESOLUTION * RESOLUTION];
|
||||
scan = true;
|
||||
chunkIt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getArea(int index) {
|
||||
if (selectedAreas[index] == null) {
|
||||
selectedAreas[index] = new MapArea();
|
||||
}
|
||||
|
||||
return selectedAreas[index];
|
||||
}
|
||||
|
||||
public void setArea(int index, MapArea area) {
|
||||
selectedAreas[index] = area;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,12 @@ public class BCDynamicTexture {
|
|||
colorMap[x + y * height] = 255 << 24 | color;
|
||||
}
|
||||
|
||||
public void setColor(int x, int y, int color, float alpha) {
|
||||
int a = (int) (alpha * 255.0F);
|
||||
|
||||
colorMap[x + y * height] = a << 24 | color;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void drawMap(int screenX, int screenY, float zLevel) {
|
||||
drawMap(screenX, screenY, zLevel, 0, 0, width, height);
|
||||
|
|
|
@ -8,12 +8,18 @@
|
|||
*/
|
||||
package buildcraft.core;
|
||||
|
||||
import net.minecraft.util.LongHashMap;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class MapArea {
|
||||
|
||||
private LongHashMap chunkMapping = new LongHashMap();
|
||||
// TODO: This can exceed 32k of data. Generalize the slicing code used
|
||||
// in tiles.
|
||||
@NetworkData
|
||||
private HashMap chunkMapping = new HashMap<Long, MapChunk>();
|
||||
|
||||
public boolean get(int x, int z) {
|
||||
int xChunk = x >> 4;
|
||||
|
@ -21,14 +27,12 @@ public class MapArea {
|
|||
long chunkId = ChunkCoordIntPair.chunkXZ2Int(xChunk, zChunk);
|
||||
MapChunk property;
|
||||
|
||||
if (!chunkMapping.containsItem(chunkId)) {
|
||||
property = new MapChunk(xChunk, zChunk);
|
||||
chunkMapping.add(chunkId, property);
|
||||
if (!chunkMapping.containsKey(chunkId)) {
|
||||
return false;
|
||||
} else {
|
||||
property = (MapChunk) chunkMapping.getValueByKey(chunkId);
|
||||
property = (MapChunk) chunkMapping.get(chunkId);
|
||||
return property.get(x & 0xF, z & 0xF);
|
||||
}
|
||||
|
||||
return property.get(x & 0xF, z & 0xF);
|
||||
}
|
||||
|
||||
public void set(int x, int z, boolean val) {
|
||||
|
@ -37,11 +41,11 @@ public class MapArea {
|
|||
long chunkId = ChunkCoordIntPair.chunkXZ2Int(xChunk, zChunk);
|
||||
MapChunk property;
|
||||
|
||||
if (!chunkMapping.containsItem(chunkId)) {
|
||||
property = new MapChunk(xChunk, zChunk);
|
||||
chunkMapping.add(chunkId, property);
|
||||
if (!chunkMapping.containsKey(chunkId)) {
|
||||
property = new MapChunk();
|
||||
chunkMapping.put(chunkId, property);
|
||||
} else {
|
||||
property = (MapChunk) chunkMapping.getValueByKey(chunkId);
|
||||
property = (MapChunk) chunkMapping.get(chunkId);
|
||||
}
|
||||
|
||||
property.set(x & 0xF, z & 0xF, val);
|
||||
|
|
|
@ -10,23 +10,49 @@ package buildcraft.core;
|
|||
|
||||
import java.util.BitSet;
|
||||
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class MapChunk {
|
||||
|
||||
@NetworkData
|
||||
private BitSet property;
|
||||
private int xPosition, zPosition;
|
||||
|
||||
public MapChunk(int iXPosition, int iZPosition) {
|
||||
property = new BitSet(16 * 16);
|
||||
xPosition = iXPosition;
|
||||
zPosition = iZPosition;
|
||||
@NetworkData
|
||||
private boolean fullSet = false;
|
||||
|
||||
public MapChunk() {
|
||||
}
|
||||
|
||||
public boolean get(int xChunk, int zChunk) {
|
||||
return property.get(xChunk * 16 + zChunk);
|
||||
if (fullSet) {
|
||||
return true;
|
||||
} else if (property == null) {
|
||||
return false;
|
||||
} else {
|
||||
return property.get(xChunk * 16 + zChunk);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int xChunk, int zChunk, boolean value) {
|
||||
property.set(xChunk * 16 + zChunk, value);
|
||||
if (property == null && !fullSet) {
|
||||
property = new BitSet(16 * 16);
|
||||
}
|
||||
|
||||
if (property == null && !value) {
|
||||
property = new BitSet(16 * 16);
|
||||
property.flip(0, 16 * 16 - 1);
|
||||
}
|
||||
|
||||
if (property != null) {
|
||||
property.set(xChunk * 16 + zChunk, value);
|
||||
}
|
||||
|
||||
if (value && !fullSet) {
|
||||
if (property.nextClearBit(0) >= 16 * 16) {
|
||||
property = null;
|
||||
fullSet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -536,4 +536,8 @@ public abstract class GuiBuildCraft extends GuiContainer {
|
|||
drawTexturedModelRectFromIcon(x, y, icon, 16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
protected BuildCraftContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.lang.reflect.Array;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
|
@ -637,6 +638,8 @@ public class ClassMapping extends ClassSerializer {
|
|||
registerSerializer(ItemStack.class, new SerializerItemStack());
|
||||
registerSerializer(FluidStack.class, new SerializerFluidStack());
|
||||
registerSerializer(Integer.class, new SerializerInteger());
|
||||
registerSerializer(Long.class, new SerializerLong());
|
||||
registerSerializer(BitSet.class, new SerializerBitSet());
|
||||
registerSerializer(INBTSerializable.class, new SerializerINBTSerializable());
|
||||
}
|
||||
}
|
||||
|
|
46
common/buildcraft/core/network/serializers/SerializerBitSet.java
Executable file
46
common/buildcraft/core/network/serializers/SerializerBitSet.java
Executable file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.core.network.serializers;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class SerializerBitSet extends ClassSerializer {
|
||||
|
||||
@Override
|
||||
public void write (ByteBuf data, Object o, SerializationContext context) {
|
||||
if (o == null) {
|
||||
data.writeBoolean(false);
|
||||
} else {
|
||||
data.writeBoolean(true);
|
||||
|
||||
BitSet set = (BitSet) o;
|
||||
byte[] bytes = set.toByteArray();
|
||||
data.writeInt(bytes.length);
|
||||
data.writeBytes(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read (ByteBuf data, Object o, SerializationContext context) {
|
||||
if (!data.readBoolean()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int actualSize = data.readInt();
|
||||
byte[] bytes = new byte[actualSize];
|
||||
data.readBytes(bytes);
|
||||
|
||||
BitSet set = new BitSet();
|
||||
set = BitSet.valueOf(bytes);
|
||||
|
||||
return set;
|
||||
}
|
||||
}
|
26
common/buildcraft/core/network/serializers/SerializerLong.java
Executable file
26
common/buildcraft/core/network/serializers/SerializerLong.java
Executable file
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.core.network.serializers;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class SerializerLong extends ClassSerializer {
|
||||
|
||||
@Override
|
||||
public void write (ByteBuf data, Object o, SerializationContext context) {
|
||||
Long i = (Long) o;
|
||||
|
||||
data.writeLong(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read (ByteBuf data, Object o, SerializationContext context) {
|
||||
return new Long(data.readLong());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue