use of buildcraft.robotics.map.MapWorld in project BuildCraft by BuildCraft.
the class TileZonePlan method recalculatePreview.
private void recalculatePreview() {
byte[] newPreviewColors = new byte[80];
MapWorld mw = BuildCraftRobotics.manager.getWorld(worldObj);
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 10; x++) {
int tx = (x * PREVIEW_BLOCKS_PER_PIXEL) - (5 * PREVIEW_BLOCKS_PER_PIXEL) + (PREVIEW_BLOCKS_PER_PIXEL / 2);
int ty = (y * PREVIEW_BLOCKS_PER_PIXEL) - (4 * PREVIEW_BLOCKS_PER_PIXEL) + (PREVIEW_BLOCKS_PER_PIXEL / 2);
newPreviewColors[y * 10 + x] = (byte) mw.getColor(getPos().getX() - (getPos().getX() % PREVIEW_BLOCKS_PER_PIXEL) + tx, getPos().getZ() - (getPos().getZ() % PREVIEW_BLOCKS_PER_PIXEL) + ty);
}
}
if (!Arrays.equals(previewColors, newPreviewColors)) {
System.arraycopy(newPreviewColors, 0, previewColors, 0, 80);
sendNetworkUpdate();
}
}
use of buildcraft.robotics.map.MapWorld in project BuildCraft by BuildCraft.
the class ContainerZonePlan method computeMap.
private void computeMap(int cx, int cz, int width, int height, float blocksPerPixel, EntityPlayer player) {
final byte[] textureData = new byte[width * height];
MapWorld w = BuildCraftRobotics.manager.getWorld(map.getWorld());
int startX = Math.round(cx - width * blocksPerPixel / 2);
int startZ = Math.round(cz - height * blocksPerPixel / 2);
int mapStartX = map.chunkStartX << 4;
int mapStartZ = map.chunkStartZ << 4;
for (int j = 0; j < height; ++j) {
for (int i = 0; i < width; ++i) {
int x = Math.round(startX + i * blocksPerPixel);
int z = Math.round(startZ + j * blocksPerPixel);
int ix = x - mapStartX;
int iz = z - mapStartZ;
if (ix >= 0 && iz >= 0 && ix < TileZonePlan.RESOLUTION && iz < TileZonePlan.RESOLUTION) {
textureData[i + j * width] = (byte) w.getColor(x, z);
}
}
}
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() {
@Override
public void write(ByteBuf data) {
data.writeMedium(textureData.length);
data.writeMedium(pos);
data.writeBytes(textureData, pos, Math.min(textureData.length - pos, len));
}
}));
}
}
Aggregations