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.TilePathMarker;
|
||||
import buildcraft.builders.blueprints.BlueprintDatabase;
|
||||
import buildcraft.builders.schematics.SchematicAir;
|
||||
import buildcraft.builders.schematics.SchematicBed;
|
||||
import buildcraft.builders.schematics.SchematicBlockCreative;
|
||||
import buildcraft.builders.schematics.SchematicCactus;
|
||||
|
@ -280,6 +281,8 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
|||
|
||||
// Standard blocks
|
||||
ISchematicRegistry schemes = BuilderAPI.schematicRegistry;
|
||||
schemes.registerSchematicBlock(Blocks.air, SchematicAir.class);
|
||||
|
||||
schemes.registerSchematicBlock(Blocks.snow, SchematicIgnore.class);
|
||||
schemes.registerSchematicBlock(Blocks.tallgrass, SchematicIgnore.class);
|
||||
schemes.registerSchematicBlock(Blocks.double_plant, SchematicIgnore.class);
|
||||
|
|
|
@ -63,7 +63,7 @@ public final class HeuristicBlockDetection {
|
|||
if (creativeOnly) {
|
||||
SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicBlockCreative.class);
|
||||
} else {
|
||||
if (block instanceof IFluidBlock) {
|
||||
if (block instanceof IFluidBlock) {
|
||||
IFluidBlock fblock = (IFluidBlock) block;
|
||||
if (fblock.getFluid() != null) {
|
||||
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;
|
||||
|
||||
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 net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -82,9 +87,10 @@ public class ContainerZonePlan extends BuildCraftContainer implements ICommandRe
|
|||
currentAreaSelection.readData(stream);
|
||||
gui.refreshSelectedArea();
|
||||
} else if ("receiveImage".equals(command)) {
|
||||
int size = stream.readUnsignedShort();
|
||||
int size = stream.readUnsignedMedium();
|
||||
|
||||
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()) {
|
||||
|
@ -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) {
|
||||
mapTexture = new BCDynamicTexture(width, height);
|
||||
final byte[] textureData = new byte[width * height];
|
||||
|
||||
int startX = cx - width * blocksPerPixel / 2;
|
||||
int startZ = cz - height * blocksPerPixel / 2;
|
||||
|
||||
for (int i = 0; i < width; ++i) {
|
||||
for (int j = 0; j < height; ++j) {
|
||||
double r = 0;
|
||||
double g = 0;
|
||||
double b = 0;
|
||||
int x = startX + i * blocksPerPixel;
|
||||
int z = startZ + j * blocksPerPixel;
|
||||
int ix = x - (map.chunkStartX << 4);
|
||||
int iz = z - (map.chunkStartZ << 4);
|
||||
|
||||
for (int stepi = 0; stepi < blocksPerPixel; ++stepi) {
|
||||
for (int stepj = 0; stepj < blocksPerPixel; ++stepj) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (ix >= 0 && iz >= 0 && ix < TileZonePlan.RESOLUTION && iz < TileZonePlan.RESOLUTION) {
|
||||
textureData[i + j * width] = map.colors[ix + iz * TileZonePlan.RESOLUTION];
|
||||
}
|
||||
|
||||
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() {
|
||||
public void write(ByteBuf data) {
|
||||
data.writeShort(mapTexture.colorMap.length);
|
||||
for (int i = 0; i < mapTexture.colorMap.length; i++) {
|
||||
data.writeInt(mapTexture.colorMap[i]);
|
||||
}
|
||||
data.writeMedium(textureData.length);
|
||||
data.writeBytes(textureData);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -9,12 +9,14 @@
|
|||
package buildcraft.commander;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.core.ItemMapLocation;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.ZonePlan;
|
||||
|
@ -39,6 +41,8 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
|
||||
private SimpleInventory inv = new SimpleInventory(2, "inv", 64);
|
||||
|
||||
private SafeTimeTracker zonePlannerScanning = new SafeTimeTracker(5);
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
@ -103,7 +107,7 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
return;
|
||||
}
|
||||
|
||||
if (scan) {
|
||||
if (scan && zonePlannerScanning.markTimeIfDelay(worldObj)) {
|
||||
int[] coords = getCoords();
|
||||
Chunk chunk = worldObj.getChunkFromChunkCoords(coords[0], coords[1]);
|
||||
loadChunk(chunk);
|
||||
|
@ -147,11 +151,11 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
int x = (chunk.xPosition << 4) + cx;
|
||||
int z = (chunk.zPosition << 4) + cz;
|
||||
|
||||
int color = 0;
|
||||
|
||||
for (int y = getWorldObj().getHeight() - 1; y >= 0; --y) {
|
||||
if (!chunk.getBlock(cx, y, cz).isAir(worldObj, x, y, z)) {
|
||||
color = chunk.getBlock(cx, y, cz).getMapColor(0).colorIndex;
|
||||
int y = getWorldObj().getHeightValue(x, z);
|
||||
int color;
|
||||
while ((color = chunk.getBlock(cx, y, cz).getMapColor(0).colorIndex) == MapColor.airColor.colorIndex) {
|
||||
y--;
|
||||
if (y < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +197,7 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
chunkIt = nbt.getInteger("chunkIt");
|
||||
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];
|
||||
scan = true;
|
||||
chunkIt = 0;
|
||||
|
|
|
@ -116,7 +116,7 @@ public final class SchematicRegistry implements ISchematicRegistry {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue