optimize zone planners, fix #2243
This commit is contained in:
parent
cc7d3397f5
commit
6858738d4d
6 changed files with 46 additions and 44 deletions
|
@ -76,6 +76,7 @@ import buildcraft.builders.TileFiller;
|
||||||
import buildcraft.builders.TileMarker;
|
import buildcraft.builders.TileMarker;
|
||||||
import buildcraft.builders.TilePathMarker;
|
import buildcraft.builders.TilePathMarker;
|
||||||
import buildcraft.builders.blueprints.BlueprintDatabase;
|
import buildcraft.builders.blueprints.BlueprintDatabase;
|
||||||
|
import buildcraft.builders.schematics.SchematicAir;
|
||||||
import buildcraft.builders.schematics.SchematicBed;
|
import buildcraft.builders.schematics.SchematicBed;
|
||||||
import buildcraft.builders.schematics.SchematicBlockCreative;
|
import buildcraft.builders.schematics.SchematicBlockCreative;
|
||||||
import buildcraft.builders.schematics.SchematicCactus;
|
import buildcraft.builders.schematics.SchematicCactus;
|
||||||
|
@ -280,6 +281,8 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
||||||
|
|
||||||
// Standard blocks
|
// Standard blocks
|
||||||
ISchematicRegistry schemes = BuilderAPI.schematicRegistry;
|
ISchematicRegistry schemes = BuilderAPI.schematicRegistry;
|
||||||
|
schemes.registerSchematicBlock(Blocks.air, SchematicAir.class);
|
||||||
|
|
||||||
schemes.registerSchematicBlock(Blocks.snow, SchematicIgnore.class);
|
schemes.registerSchematicBlock(Blocks.snow, SchematicIgnore.class);
|
||||||
schemes.registerSchematicBlock(Blocks.tallgrass, SchematicIgnore.class);
|
schemes.registerSchematicBlock(Blocks.tallgrass, SchematicIgnore.class);
|
||||||
schemes.registerSchematicBlock(Blocks.double_plant, SchematicIgnore.class);
|
schemes.registerSchematicBlock(Blocks.double_plant, SchematicIgnore.class);
|
||||||
|
|
|
@ -63,7 +63,7 @@ public final class HeuristicBlockDetection {
|
||||||
if (creativeOnly) {
|
if (creativeOnly) {
|
||||||
SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicBlockCreative.class);
|
SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicBlockCreative.class);
|
||||||
} else {
|
} else {
|
||||||
if (block instanceof IFluidBlock) {
|
if (block instanceof IFluidBlock) {
|
||||||
IFluidBlock fblock = (IFluidBlock) block;
|
IFluidBlock fblock = (IFluidBlock) block;
|
||||||
if (fblock.getFluid() != null) {
|
if (fblock.getFluid() != null) {
|
||||||
SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicFluid.class, new FluidStack(fblock.getFluid(), 1000));
|
SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicFluid.class, new FluidStack(fblock.getFluid(), 1000));
|
||||||
|
|
13
common/buildcraft/builders/schematics/SchematicAir.java
Normal file
13
common/buildcraft/builders/schematics/SchematicAir.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package buildcraft.builders.schematics;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import buildcraft.api.blueprints.IBuilderContext;
|
||||||
|
import buildcraft.api.blueprints.SchematicBlock;
|
||||||
|
|
||||||
|
public class SchematicAir extends SchematicBlock {
|
||||||
|
@Override
|
||||||
|
public void getRequirementsForPlacement(IBuilderContext context, LinkedList<ItemStack> requirements) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,11 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.commander;
|
package buildcraft.commander;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
import java.util.zip.Deflater;
|
||||||
|
import java.util.zip.Inflater;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.block.material.MapColor;
|
import net.minecraft.block.material.MapColor;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -82,9 +87,10 @@ public class ContainerZonePlan extends BuildCraftContainer implements ICommandRe
|
||||||
currentAreaSelection.readData(stream);
|
currentAreaSelection.readData(stream);
|
||||||
gui.refreshSelectedArea();
|
gui.refreshSelectedArea();
|
||||||
} else if ("receiveImage".equals(command)) {
|
} else if ("receiveImage".equals(command)) {
|
||||||
int size = stream.readUnsignedShort();
|
int size = stream.readUnsignedMedium();
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
mapTexture.colorMap[i] = stream.readInt();
|
mapTexture.colorMap[i] = 0xFF000000 | MapColor.mapColorArray[stream.readUnsignedByte()].colorValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (side.isServer()) {
|
} else if (side.isServer()) {
|
||||||
|
@ -109,52 +115,28 @@ public class ContainerZonePlan extends BuildCraftContainer implements ICommandRe
|
||||||
}
|
}
|
||||||
|
|
||||||
private void computeMap(int cx, int cz, int width, int height, int blocksPerPixel, EntityPlayer player) {
|
private void computeMap(int cx, int cz, int width, int height, int blocksPerPixel, EntityPlayer player) {
|
||||||
mapTexture = new BCDynamicTexture(width, height);
|
final byte[] textureData = new byte[width * height];
|
||||||
|
|
||||||
int startX = cx - width * blocksPerPixel / 2;
|
int startX = cx - width * blocksPerPixel / 2;
|
||||||
int startZ = cz - height * blocksPerPixel / 2;
|
int startZ = cz - height * blocksPerPixel / 2;
|
||||||
|
|
||||||
for (int i = 0; i < width; ++i) {
|
for (int i = 0; i < width; ++i) {
|
||||||
for (int j = 0; j < height; ++j) {
|
for (int j = 0; j < height; ++j) {
|
||||||
double r = 0;
|
int x = startX + i * blocksPerPixel;
|
||||||
double g = 0;
|
int z = startZ + j * blocksPerPixel;
|
||||||
double b = 0;
|
int ix = x - (map.chunkStartX << 4);
|
||||||
|
int iz = z - (map.chunkStartZ << 4);
|
||||||
|
|
||||||
for (int stepi = 0; stepi < blocksPerPixel; ++stepi) {
|
if (ix >= 0 && iz >= 0 && ix < TileZonePlan.RESOLUTION && iz < TileZonePlan.RESOLUTION) {
|
||||||
for (int stepj = 0; stepj < blocksPerPixel; ++stepj) {
|
textureData[i + j * width] = map.colors[ix + iz * TileZonePlan.RESOLUTION];
|
||||||
int x = startX + i * blocksPerPixel + stepi;
|
|
||||||
int z = startZ + j * blocksPerPixel + stepj;
|
|
||||||
int ix = x - (map.chunkStartX << 4);
|
|
||||||
int iz = z - (map.chunkStartZ << 4);
|
|
||||||
|
|
||||||
if (ix > 0 && ix < TileZonePlan.RESOLUTION && iz > 0 && iz < TileZonePlan.RESOLUTION) {
|
|
||||||
int color = MapColor.mapColorArray[map.colors[ix + iz * TileZonePlan.RESOLUTION]].colorValue;
|
|
||||||
|
|
||||||
r += (color >> 16) & 255;
|
|
||||||
g += (color >> 8) & 255;
|
|
||||||
b += color & 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r /= blocksPerPixel * blocksPerPixel;
|
|
||||||
g /= blocksPerPixel * blocksPerPixel;
|
|
||||||
b /= blocksPerPixel * blocksPerPixel;
|
|
||||||
|
|
||||||
r /= 255F;
|
|
||||||
g /= 255F;
|
|
||||||
b /= 255F;
|
|
||||||
|
|
||||||
mapTexture.setColor(i, j, r, g, b, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "receiveImage", new CommandWriter() {
|
BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "receiveImage", new CommandWriter() {
|
||||||
public void write(ByteBuf data) {
|
public void write(ByteBuf data) {
|
||||||
data.writeShort(mapTexture.colorMap.length);
|
data.writeMedium(textureData.length);
|
||||||
for (int i = 0; i < mapTexture.colorMap.length; i++) {
|
data.writeBytes(textureData);
|
||||||
data.writeInt(mapTexture.colorMap[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,14 @@
|
||||||
package buildcraft.commander;
|
package buildcraft.commander;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.block.material.MapColor;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
import buildcraft.api.core.SafeTimeTracker;
|
||||||
import buildcraft.core.ItemMapLocation;
|
import buildcraft.core.ItemMapLocation;
|
||||||
import buildcraft.core.TileBuildCraft;
|
import buildcraft.core.TileBuildCraft;
|
||||||
import buildcraft.core.ZonePlan;
|
import buildcraft.core.ZonePlan;
|
||||||
|
@ -39,6 +41,8 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
||||||
|
|
||||||
private SimpleInventory inv = new SimpleInventory(2, "inv", 64);
|
private SimpleInventory inv = new SimpleInventory(2, "inv", 64);
|
||||||
|
|
||||||
|
private SafeTimeTracker zonePlannerScanning = new SafeTimeTracker(5);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
@ -103,7 +107,7 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scan) {
|
if (scan && zonePlannerScanning.markTimeIfDelay(worldObj)) {
|
||||||
int[] coords = getCoords();
|
int[] coords = getCoords();
|
||||||
Chunk chunk = worldObj.getChunkFromChunkCoords(coords[0], coords[1]);
|
Chunk chunk = worldObj.getChunkFromChunkCoords(coords[0], coords[1]);
|
||||||
loadChunk(chunk);
|
loadChunk(chunk);
|
||||||
|
@ -147,11 +151,11 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
||||||
int x = (chunk.xPosition << 4) + cx;
|
int x = (chunk.xPosition << 4) + cx;
|
||||||
int z = (chunk.zPosition << 4) + cz;
|
int z = (chunk.zPosition << 4) + cz;
|
||||||
|
|
||||||
int color = 0;
|
int y = getWorldObj().getHeightValue(x, z);
|
||||||
|
int color;
|
||||||
for (int y = getWorldObj().getHeight() - 1; y >= 0; --y) {
|
while ((color = chunk.getBlock(cx, y, cz).getMapColor(0).colorIndex) == MapColor.airColor.colorIndex) {
|
||||||
if (!chunk.getBlock(cx, y, cz).isAir(worldObj, x, y, z)) {
|
y--;
|
||||||
color = chunk.getBlock(cx, y, cz).getMapColor(0).colorIndex;
|
if (y < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,7 +197,7 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
||||||
chunkIt = nbt.getInteger("chunkIt");
|
chunkIt = nbt.getInteger("chunkIt");
|
||||||
colors = nbt.getByteArray("colors");
|
colors = nbt.getByteArray("colors");
|
||||||
|
|
||||||
if (colors.length != RESOLUTION * RESOLUTION || chunkIt >= colors.length) {
|
if (colors.length != RESOLUTION * RESOLUTION || chunkIt >= RESOLUTION_CHUNKS * RESOLUTION_CHUNKS) {
|
||||||
colors = new byte[RESOLUTION * RESOLUTION];
|
colors = new byte[RESOLUTION * RESOLUTION];
|
||||||
scan = true;
|
scan = true;
|
||||||
chunkIt = 0;
|
chunkIt = 0;
|
||||||
|
|
|
@ -116,7 +116,7 @@ public final class SchematicRegistry implements ISchematicRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SchematicBlock createSchematicBlock(Block block, int metadata) {
|
public SchematicBlock createSchematicBlock(Block block, int metadata) {
|
||||||
if (block == null || block == Blocks.air || metadata < 0 || metadata >= 16) {
|
if (block == null || metadata < 0 || metadata >= 16) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue