robots can now work on a zone defined from a map
This commit is contained in:
parent
b117a23c5d
commit
e155b9b761
37 changed files with 738 additions and 373 deletions
|
@ -8,14 +8,12 @@
|
|||
*/
|
||||
package buildcraft.api.core;
|
||||
|
||||
public interface IBox {
|
||||
public interface IBox extends IZone {
|
||||
|
||||
IBox expand(int amount);
|
||||
|
||||
IBox contract(int amount);
|
||||
|
||||
boolean contains(double x, double y, double z);
|
||||
|
||||
Position pMin();
|
||||
|
||||
Position pMax();
|
||||
|
|
21
api/buildcraft/api/core/IZone.java
Executable file
21
api/buildcraft/api/core/IZone.java
Executable file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* 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.api.core;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public interface IZone {
|
||||
|
||||
double distanceTo(BlockIndex index);
|
||||
|
||||
boolean contains(double x, double y, double z);
|
||||
|
||||
BlockIndex getRandomBlockIndex(Random rand);
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.api.boards.RedstoneBoardRobot;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
|
||||
public abstract class EntityRobotBase extends EntityLiving implements IInventory {
|
||||
|
||||
|
@ -54,7 +54,7 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory
|
|||
|
||||
public abstract boolean linkToStation(IDockingStation station);
|
||||
|
||||
public abstract IBox getAreaToWork();
|
||||
public abstract IZone getZoneToWork();
|
||||
|
||||
public abstract boolean containsItems();
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.3 KiB |
BIN
buildcraft_resources/assets/buildcraft/textures/items/map_zone.png
Executable file
BIN
buildcraft_resources/assets/buildcraft/textures/items/map_zone.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 252 B |
|
@ -35,7 +35,7 @@ import buildcraft.api.recipes.BuildcraftRecipeRegistry;
|
|||
import buildcraft.api.transport.PipeWire;
|
||||
import buildcraft.builders.schematics.SchematicRotateMeta;
|
||||
import buildcraft.commander.BlockMap;
|
||||
import buildcraft.commander.TileMap;
|
||||
import buildcraft.commander.TileZonePlan;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.InterModComms;
|
||||
import buildcraft.core.ItemBuildCraft;
|
||||
|
@ -102,7 +102,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
public static ItemRedstoneBoard redstoneBoard;
|
||||
public static BlockLaser laserBlock;
|
||||
public static BlockLaserTable assemblyTableBlock;
|
||||
public static BlockMap mapBlock;
|
||||
public static BlockMap zonePlanBlock;
|
||||
|
||||
@Mod.Instance("BuildCraft|Silicon")
|
||||
public static BuildCraftSilicon instance;
|
||||
|
@ -134,9 +134,9 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
assemblyTableBlock = new BlockLaserTable();
|
||||
CoreProxy.proxy.registerBlock(assemblyTableBlock, ItemLaserTable.class);
|
||||
|
||||
mapBlock = new BlockMap();
|
||||
mapBlock.setBlockName("map");
|
||||
CoreProxy.proxy.registerBlock(mapBlock);
|
||||
zonePlanBlock = new BlockMap();
|
||||
zonePlanBlock.setBlockName("zonePlan");
|
||||
CoreProxy.proxy.registerBlock(zonePlanBlock);
|
||||
|
||||
redstoneChipset = new ItemRedstoneChipset();
|
||||
redstoneChipset.setUnlocalizedName("redstoneChipset");
|
||||
|
@ -184,7 +184,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
CoreProxy.proxy.registerTileEntity(TileAssemblyTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyTable");
|
||||
CoreProxy.proxy.registerTileEntity(TileAdvancedCraftingTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyAdvancedWorkbench");
|
||||
CoreProxy.proxy.registerTileEntity(TileIntegrationTable.class, "net.minecraft.src.buildcraft.factory.TileIntegrationTable");
|
||||
CoreProxy.proxy.registerTileEntity(TileMap.class, "net.minecraft.src.buildcraft.commander.TileMap");
|
||||
CoreProxy.proxy.registerTileEntity(TileZonePlan.class, "net.minecraft.src.buildcraft.commander.TileZonePlan");
|
||||
|
||||
SchematicRegistry.registerSchematicBlock(laserBlock, SchematicRotateMeta.class, new int[]{2, 5, 3, 4}, true);
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ import buildcraft.builders.gui.GuiFiller;
|
|||
import buildcraft.builders.urbanism.ContainerUrbanist;
|
||||
import buildcraft.builders.urbanism.GuiUrbanist;
|
||||
import buildcraft.builders.urbanism.TileUrbanist;
|
||||
import buildcraft.commander.ContainerMap;
|
||||
import buildcraft.commander.GuiMap;
|
||||
import buildcraft.commander.TileMap;
|
||||
import buildcraft.commander.ContainerZonePlan;
|
||||
import buildcraft.commander.GuiZonePlan;
|
||||
import buildcraft.commander.TileZonePlan;
|
||||
import buildcraft.core.GuiIds;
|
||||
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
|
@ -73,10 +73,10 @@ public class GuiHandler implements IGuiHandler {
|
|||
return new GuiUrbanist(player.inventory, (TileUrbanist) tile);
|
||||
|
||||
case GuiIds.MAP:
|
||||
if (!(tile instanceof TileMap)) {
|
||||
if (!(tile instanceof TileZonePlan)) {
|
||||
return null;
|
||||
}
|
||||
return new GuiMap(player.inventory, (TileMap) tile);
|
||||
return new GuiZonePlan(player.inventory, (TileZonePlan) tile);
|
||||
|
||||
default:
|
||||
return null;
|
||||
|
@ -127,10 +127,10 @@ public class GuiHandler implements IGuiHandler {
|
|||
}
|
||||
|
||||
case GuiIds.MAP:
|
||||
if (!(tile instanceof TileMap)) {
|
||||
if (!(tile instanceof TileZonePlan)) {
|
||||
return null;
|
||||
} else {
|
||||
return new ContainerMap((TileMap) tile);
|
||||
return new ContainerZonePlan(player.inventory, (TileZonePlan) tile);
|
||||
}
|
||||
|
||||
default:
|
||||
|
|
|
@ -25,7 +25,7 @@ public class BlockMap extends BlockBuildCraft {
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
return new TileMap();
|
||||
return new TileZonePlan();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* 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.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 {
|
||||
|
||||
private TileMap map;
|
||||
public MapArea currentAreaSelection;
|
||||
public GuiMap gui;
|
||||
|
||||
public ContainerMap(TileMap iMap) {
|
||||
super(0);
|
||||
|
||||
map = iMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer p_75145_1_) {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
133
common/buildcraft/commander/ContainerZonePlan.java
Executable file
133
common/buildcraft/commander/ContainerZonePlan.java
Executable file
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* 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.commander;
|
||||
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
import buildcraft.core.BCDynamicTexture;
|
||||
import buildcraft.core.ZonePlan;
|
||||
import buildcraft.core.gui.BuildCraftContainer;
|
||||
import buildcraft.core.gui.slots.SlotOutput;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.network.RPCMessageInfo;
|
||||
import buildcraft.core.network.RPCSide;
|
||||
|
||||
public class ContainerZonePlan extends BuildCraftContainer {
|
||||
|
||||
public BCDynamicTexture mapTexture;
|
||||
public ZonePlan currentAreaSelection;
|
||||
public GuiZonePlan gui;
|
||||
|
||||
private TileZonePlan map;
|
||||
|
||||
public ContainerZonePlan(IInventory playerInventory, TileZonePlan iZonePlan) {
|
||||
super(0);
|
||||
|
||||
map = iZonePlan;
|
||||
|
||||
addSlotToContainer(new Slot(iZonePlan, 0, 233, 20));
|
||||
addSlotToContainer(new SlotOutput(iZonePlan, 1, 233, 68));
|
||||
|
||||
// Player inventory
|
||||
for (int l = 0; l < 3; l++) {
|
||||
for (int k1 = 0; k1 < 9; k1++) {
|
||||
addSlotToContainer(new Slot(playerInventory, k1 + l * 9 + 9, 88 + k1 * 18, 138 + l * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i1 = 0; i1 < 9; i1++) {
|
||||
addSlotToContainer(new Slot(playerInventory, i1, 88 + i1 * 18, 196));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer p_75145_1_) {
|
||||
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.selectArea(index));
|
||||
}
|
||||
|
||||
@RPC(RPCSide.SERVER)
|
||||
private void rpcSaveArea(int index, ZonePlan area) {
|
||||
map.setArea(index, area);
|
||||
}
|
||||
|
||||
@RPC(RPCSide.CLIENT)
|
||||
private void rpcAreaLoaded(ZonePlan areaSelection) {
|
||||
currentAreaSelection = areaSelection;
|
||||
gui.refreshSelectedArea();
|
||||
}
|
||||
|
||||
@RPC(RPCSide.SERVER)
|
||||
private void computeMap(int cx, int cz, int width, int height, int blocksPerPixel, RPCMessageInfo info) {
|
||||
mapTexture = new BCDynamicTexture(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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r /= (blocksPerPixel * blocksPerPixel);
|
||||
g /= (blocksPerPixel * blocksPerPixel);
|
||||
b /= (blocksPerPixel * blocksPerPixel);
|
||||
|
||||
r /= 255F;
|
||||
g /= 255F;
|
||||
b /= 255F;
|
||||
|
||||
mapTexture.setColor(i, j, r, g, b, 1);
|
||||
}
|
||||
}
|
||||
|
||||
RPCHandler.rpcPlayer(info.sender, this, "receiveImage", mapTexture.colorMap);
|
||||
}
|
||||
|
||||
@RPC(RPCSide.CLIENT)
|
||||
private void receiveImage(int[] colors) {
|
||||
for (int i = 0; i < colors.length; ++i) {
|
||||
mapTexture.colorMap[i] = colors[i];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,17 +17,17 @@ 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.ZonePlan;
|
||||
import buildcraft.core.gui.AdvancedSlot;
|
||||
import buildcraft.core.gui.GuiAdvancedInterface;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
|
||||
public class GuiMap extends GuiAdvancedInterface {
|
||||
public class GuiZonePlan extends GuiAdvancedInterface {
|
||||
|
||||
private int mapWidth = 200;
|
||||
private int mapHeight = 100;
|
||||
|
||||
private TileMap map;
|
||||
private TileZonePlan zonePlan;
|
||||
|
||||
private BCDynamicTexture newSelection;
|
||||
private int selX1 = 0,
|
||||
|
@ -73,16 +73,16 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
}
|
||||
}
|
||||
|
||||
public GuiMap(IInventory inventory, TileMap iMap) {
|
||||
super(new ContainerMap(iMap), inventory, TMP_TEXTURE);
|
||||
public GuiZonePlan(IInventory inventory, TileZonePlan iZonePlan) {
|
||||
super(new ContainerZonePlan(inventory, iZonePlan), inventory, TMP_TEXTURE);
|
||||
|
||||
xSize = 256;
|
||||
ySize = 220;
|
||||
|
||||
map = iMap;
|
||||
zonePlan = iZonePlan;
|
||||
|
||||
map.bcTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
map.bcTexture.createDynamicTexture();
|
||||
getContainer().mapTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
getContainer().mapTexture.createDynamicTexture();
|
||||
|
||||
currentSelection = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
currentSelection.createDynamicTexture();
|
||||
|
@ -91,10 +91,10 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
newSelection.createDynamicTexture();
|
||||
|
||||
|
||||
getContainer().currentAreaSelection = new MapArea();
|
||||
getContainer().currentAreaSelection = new ZonePlan();
|
||||
|
||||
cx = map.xCoord;
|
||||
cz = map.zCoord;
|
||||
cx = zonePlan.xCoord;
|
||||
cz = zonePlan.zCoord;
|
||||
|
||||
slots = new AdvancedSlot[16];
|
||||
|
||||
|
@ -113,7 +113,8 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
}
|
||||
|
||||
private void uploadMap() {
|
||||
RPCHandler.rpcServer(map, "computeMap", cx, cz, map.bcTexture.width, map.bcTexture.height,
|
||||
RPCHandler.rpcServer(getContainer(), "computeMap", cx, cz, getContainer().mapTexture.width,
|
||||
getContainer().mapTexture.height,
|
||||
zoomLevel);
|
||||
}
|
||||
|
||||
|
@ -124,15 +125,15 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
int cornerX = (width - xSize) / 2;
|
||||
int cornerY = (height - ySize) / 2;
|
||||
|
||||
mapXMin = (width - map.bcTexture.width) / 2;
|
||||
mapXMin = (width - getContainer().mapTexture.width) / 2;
|
||||
|
||||
if (map.bcTexture.height <= 200) {
|
||||
if (getContainer().mapTexture.height <= 200) {
|
||||
mapYMin = cornerY + 20;
|
||||
} else {
|
||||
mapYMin = (height - map.bcTexture.height) / 2;
|
||||
mapYMin = (height - getContainer().mapTexture.height) / 2;
|
||||
}
|
||||
|
||||
map.bcTexture.drawMap(mapXMin, mapYMin, zLevel);
|
||||
getContainer().mapTexture.drawMap(mapXMin, mapYMin, zLevel);
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
@ -156,11 +157,13 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
if (map.bcTexture.height <= 200) {
|
||||
if (getContainer().mapTexture.height <= 200) {
|
||||
drawBackgroundSlots();
|
||||
|
||||
bindTexture(texture);
|
||||
drawTexturedModalRect(cornerX + colorSelected.x, cornerY + colorSelected.y, 0, 220, 16, 16);
|
||||
drawTexturedModalRect(cornerX + 236, cornerY + 38, 16, 220, 8,
|
||||
(int) ((zonePlan.progress / (float) TileZonePlan.CRAFT_TIME) * 27));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,8 +178,8 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
int blockStartZ = cz - mapHeight * zoomLevel / 2;
|
||||
|
||||
boolean clickOnMap = mouseX >= mapXMin
|
||||
&& mouseX <= mapXMin + map.bcTexture.width && mouseY >= mapYMin &&
|
||||
mouseY <= mapYMin + map.bcTexture.height;
|
||||
&& mouseX <= mapXMin + getContainer().mapTexture.width && mouseY >= mapYMin &&
|
||||
mouseY <= mapYMin + getContainer().mapTexture.height;
|
||||
|
||||
if (clickOnMap) {
|
||||
if (mouseButton == 1) {
|
||||
|
@ -220,8 +223,8 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
super.mouseClickMove(mouseX, mouseY, lastButtonBlicked, time);
|
||||
|
||||
if (inSelection
|
||||
&& mouseX >= mapXMin && mouseX <= mapXMin + map.bcTexture.width
|
||||
&& mouseY >= mapYMin && mouseY <= mapYMin + map.bcTexture.height) {
|
||||
&& mouseX >= mapXMin && mouseX <= mapXMin + getContainer().mapTexture.width
|
||||
&& mouseY >= mapYMin && mouseY <= mapYMin + getContainer().mapTexture.height) {
|
||||
|
||||
selX2 = mouseX;
|
||||
selY2 = mouseY;
|
||||
|
@ -275,8 +278,8 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
mapWidth = 200;
|
||||
mapHeight = 100;
|
||||
|
||||
map.bcTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
map.bcTexture.createDynamicTexture();
|
||||
getContainer().mapTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
getContainer().mapTexture.createDynamicTexture();
|
||||
|
||||
currentSelection = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
currentSelection.createDynamicTexture();
|
||||
|
@ -287,8 +290,8 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
mapWidth = this.mc.displayWidth;
|
||||
mapHeight = this.mc.displayHeight;
|
||||
|
||||
map.bcTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
map.bcTexture.createDynamicTexture();
|
||||
getContainer().mapTexture = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
getContainer().mapTexture.createDynamicTexture();
|
||||
|
||||
currentSelection = new BCDynamicTexture(mapWidth, mapHeight);
|
||||
currentSelection.createDynamicTexture();
|
||||
|
@ -345,7 +348,7 @@ public class GuiMap extends GuiAdvancedInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ContainerMap getContainer() {
|
||||
return (ContainerMap) super.getContainer();
|
||||
protected ContainerZonePlan getContainer() {
|
||||
return (ContainerZonePlan) super.getContainer();
|
||||
}
|
||||
}
|
|
@ -8,32 +8,37 @@
|
|||
*/
|
||||
package buildcraft.commander;
|
||||
|
||||
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.core.BCDynamicTexture;
|
||||
import buildcraft.core.MapArea;
|
||||
import buildcraft.api.core.NetworkData;
|
||||
import buildcraft.core.ItemMapLocation;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.network.RPCMessageInfo;
|
||||
import buildcraft.core.network.RPCSide;
|
||||
import buildcraft.core.ZonePlan;
|
||||
import buildcraft.core.inventory.SimpleInventory;
|
||||
|
||||
public class TileMap extends TileBuildCraft {
|
||||
public class TileZonePlan extends TileBuildCraft implements IInventory {
|
||||
|
||||
public static final int RESOLUTION = 2048;
|
||||
public static final int CRAFT_TIME = 120;
|
||||
private static int RESOLUTION_CHUNKS = RESOLUTION >> 4;
|
||||
|
||||
public BCDynamicTexture bcTexture;
|
||||
public int chunkStartX, chunkStartZ;
|
||||
public byte[] colors = new byte[RESOLUTION * RESOLUTION];
|
||||
|
||||
private byte[] colors = new byte[RESOLUTION * RESOLUTION];
|
||||
@NetworkData
|
||||
public int progress = 0;
|
||||
|
||||
private boolean scan = false;
|
||||
private int chunkStartX, chunkStartZ;
|
||||
private int chunkIt = 0;
|
||||
|
||||
private MapArea[] selectedAreas = new MapArea[16];
|
||||
private ZonePlan[] selectedAreas = new ZonePlan[16];
|
||||
private int currentSelectedArea = 0;
|
||||
|
||||
private SimpleInventory inv = new SimpleInventory(2, "inv", 64);
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
@ -111,81 +116,32 @@ public class TileMap extends TileBuildCraft {
|
|||
chunkIt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RPC(RPCSide.SERVER)
|
||||
private void computeMap(int cx, int cz, int width, int height, int blocksPerPixel, RPCMessageInfo info) {
|
||||
bcTexture = new BCDynamicTexture(width, height);
|
||||
if (inv.getStackInSlot(0) != null
|
||||
&& inv.getStackInSlot(1) == null
|
||||
&& inv.getStackInSlot(0).getItem() instanceof ItemMapLocation) {
|
||||
|
||||
int startX = cx - width * blocksPerPixel / 2;
|
||||
int startZ = cz - height * blocksPerPixel / 2;
|
||||
if (progress < CRAFT_TIME) {
|
||||
progress++;
|
||||
|
||||
for (int i = 0; i < width; ++i) {
|
||||
for (int j = 0; j < height; ++j) {
|
||||
double r = 0;
|
||||
double g = 0;
|
||||
double b = 0;
|
||||
if (worldObj.getTotalWorldTime() % 5 == 0) {
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
} else {
|
||||
ItemStack stack = inv.decrStackSize(0, 1);
|
||||
|
||||
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 - (chunkStartX << 4);
|
||||
int iz = z - (chunkStartX << 4);
|
||||
|
||||
if (ix > 0 && ix < RESOLUTION && iz > 0 && iz < RESOLUTION) {
|
||||
int color = MapColor.mapColorArray[colors[ix + iz * RESOLUTION]].colorValue;
|
||||
|
||||
r += (color >> 16) & 255;
|
||||
g += (color >> 8) & 255;
|
||||
b += color & 255;
|
||||
}
|
||||
}
|
||||
if (selectedAreas[currentSelectedArea] != null) {
|
||||
ItemMapLocation.setZone(stack, selectedAreas[currentSelectedArea]);
|
||||
}
|
||||
|
||||
r /= (blocksPerPixel * blocksPerPixel);
|
||||
g /= (blocksPerPixel * blocksPerPixel);
|
||||
b /= (blocksPerPixel * blocksPerPixel);
|
||||
|
||||
r /= 255F;
|
||||
g /= 255F;
|
||||
b /= 255F;
|
||||
|
||||
bcTexture.setColor(i, j, r, g, b, 1);
|
||||
inv.setInventorySlotContents(1, stack);
|
||||
}
|
||||
}
|
||||
|
||||
RPCHandler.rpcPlayer(info.sender, this, "receiveImage", bcTexture.colorMap);
|
||||
}
|
||||
|
||||
@RPC(RPCSide.CLIENT)
|
||||
private void receiveImage(int[] colors) {
|
||||
for (int i = 0; i < colors.length; ++i) {
|
||||
bcTexture.colorMap[i] = colors[i];
|
||||
} else if (progress != 0) {
|
||||
progress = 0;
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void setColor(int[] map, int width, int height, int index, double r, double g, double b, double a) {
|
||||
int i = (int) (a * 255.0F);
|
||||
int j = (int) (r * 255.0F);
|
||||
int k = (int) (g * 255.0F);
|
||||
int l = (int) (b * 255.0F);
|
||||
map[index] = i << 24 | j << 16 | k << 8 | l;
|
||||
}
|
||||
|
||||
private void setColor(int[] map, int width, int height, int x, int y, double r, double g, double b, double a) {
|
||||
int i = (int) (a * 255.0F);
|
||||
int j = (int) (r * 255.0F);
|
||||
int k = (int) (g * 255.0F);
|
||||
int l = (int) (b * 255.0F);
|
||||
map[x + y * width] = i << 24 | j << 16 | k << 8 | l;
|
||||
}
|
||||
|
||||
private void setColor(int[] map, int width, int height, int x, int y, int color) {
|
||||
map[x + y * width] = 255 << 24 | color;
|
||||
}
|
||||
|
||||
|
||||
private void loadChunk(Chunk chunk) {
|
||||
for (int cx = 0; cx < 16; ++cx) {
|
||||
for (int cz = 0; cz < 16; ++cz) {
|
||||
|
@ -216,6 +172,10 @@ public class TileMap extends TileBuildCraft {
|
|||
nbt.setBoolean("scan", scan);
|
||||
nbt.setInteger("chunkIt", chunkIt);
|
||||
nbt.setByteArray("colors", colors);
|
||||
|
||||
NBTTagCompound invNBT = new NBTTagCompound();
|
||||
inv.writeToNBT(invNBT);
|
||||
nbt.setTag("inv", invNBT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -231,17 +191,82 @@ public class TileMap extends TileBuildCraft {
|
|||
scan = true;
|
||||
chunkIt = 0;
|
||||
}
|
||||
|
||||
inv.readFromNBT(nbt.getCompoundTag("inv"));
|
||||
}
|
||||
|
||||
public Object getArea(int index) {
|
||||
public Object selectArea(int index) {
|
||||
if (selectedAreas[index] == null) {
|
||||
selectedAreas[index] = new MapArea();
|
||||
selectedAreas[index] = new ZonePlan();
|
||||
}
|
||||
|
||||
currentSelectedArea = index;
|
||||
|
||||
return selectedAreas[index];
|
||||
}
|
||||
|
||||
public void setArea(int index, MapArea area) {
|
||||
public void setArea(int index, ZonePlan area) {
|
||||
selectedAreas[index] = area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inv.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slotId) {
|
||||
return inv.getStackInSlot(slotId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count) {
|
||||
return inv.decrStackSize(slotId, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slotId) {
|
||||
return inv.getStackInSlotOnClosing(slotId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotId, ItemStack itemstack) {
|
||||
inv.setInventorySlotContents(slotId, itemstack);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return inv.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return inv.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return inv.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
inv.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
inv.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return inv.isItemValidForSlot(i, itemstack);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ package buildcraft.core;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
|
@ -353,4 +354,23 @@ public class Box implements IBox {
|
|||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double distanceTo(BlockIndex index) {
|
||||
int dx = index.x - (xMin + (xMax - xMin + 1));
|
||||
int dy = index.y - (yMin + (yMax - yMin + 1));
|
||||
int dz = index.z - (zMin + (zMax - zMin + 1));
|
||||
|
||||
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockIndex getRandomBlockIndex(Random rand) {
|
||||
int x = xMin + rand.nextInt(xMax - xMin);
|
||||
int y = yMin + rand.nextInt(yMax - yMin);
|
||||
int z = zMin + rand.nextInt(zMax - zMin);
|
||||
|
||||
return new BlockIndex(x, y, z);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
55
common/buildcraft/core/ChunkIndex.java
Executable file
55
common/buildcraft/core/ChunkIndex.java
Executable file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class ChunkIndex {
|
||||
|
||||
@NetworkData
|
||||
public int x, z;
|
||||
|
||||
public ChunkIndex() {
|
||||
|
||||
}
|
||||
|
||||
public ChunkIndex(int iX, int iZ) {
|
||||
x = iX;
|
||||
z = iZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ChunkIndex) {
|
||||
ChunkIndex c = (ChunkIndex) obj;
|
||||
|
||||
return c.x == x && c.z == z;
|
||||
}
|
||||
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (x * 37 + z);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("x", x);
|
||||
nbt.setInteger("z", z);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
x = nbt.getInteger("x");
|
||||
z = nbt.getInteger("z");
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
import buildcraft.api.boards.RedstoneBoardRegistry;
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.builders.TileMarker;
|
||||
import buildcraft.builders.TilePathMarker;
|
||||
import buildcraft.core.utils.NBTUtils;
|
||||
|
@ -39,6 +40,7 @@ public class ItemMapLocation extends ItemBuildCraft {
|
|||
public IIcon spot;
|
||||
public IIcon area;
|
||||
public IIcon path;
|
||||
public IIcon zone;
|
||||
|
||||
public ItemMapLocation() {
|
||||
super(CreativeTabBuildCraft.ITEMS);
|
||||
|
@ -87,6 +89,9 @@ public class ItemMapLocation extends ItemBuildCraft {
|
|||
list.add(StringUtils.localize("{" + x + ", " + y + ", " + z + "} + " + pathNBT.tagCount() + " elements"));
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,6 +116,9 @@ public class ItemMapLocation extends ItemBuildCraft {
|
|||
case 2:
|
||||
itemIcon = path;
|
||||
break;
|
||||
case 3:
|
||||
itemIcon = zone;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,6 +132,7 @@ public class ItemMapLocation extends ItemBuildCraft {
|
|||
spot = par1IconRegister.registerIcon("buildcraft:map_spot");
|
||||
area = par1IconRegister.registerIcon("buildcraft:map_area");
|
||||
path = par1IconRegister.registerIcon("buildcraft:map_path");
|
||||
zone = par1IconRegister.registerIcon("buildcraft:map_zone");
|
||||
|
||||
RedstoneBoardRegistry.instance.registerIcons(par1IconRegister);
|
||||
}
|
||||
|
@ -212,4 +221,26 @@ public class ItemMapLocation extends ItemBuildCraft {
|
|||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static IZone getZone(ItemStack item) {
|
||||
NBTTagCompound cpt = NBTUtils.getItemData(item);
|
||||
|
||||
if (cpt.hasKey("kind") && cpt.getByte("kind") == 3) {
|
||||
ZonePlan plan = new ZonePlan();
|
||||
plan.readFromNBT(cpt);
|
||||
|
||||
return plan;
|
||||
} else if (cpt.hasKey("kind") && cpt.getByte("kind") == 1) {
|
||||
return getBox(item);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setZone(ItemStack item, ZonePlan plan) {
|
||||
NBTTagCompound cpt = NBTUtils.getItemData(item);
|
||||
|
||||
cpt.setByte("kind", (byte) 3);
|
||||
plan.writeToNBT(cpt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class MapArea {
|
||||
|
||||
// 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;
|
||||
int zChunk = z >> 4;
|
||||
long chunkId = ChunkCoordIntPair.chunkXZ2Int(xChunk, zChunk);
|
||||
MapChunk property;
|
||||
|
||||
if (!chunkMapping.containsKey(chunkId)) {
|
||||
return false;
|
||||
} else {
|
||||
property = (MapChunk) chunkMapping.get(chunkId);
|
||||
return property.get(x & 0xF, z & 0xF);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int x, int z, boolean val) {
|
||||
int xChunk = x >> 4;
|
||||
int zChunk = z >> 4;
|
||||
long chunkId = ChunkCoordIntPair.chunkXZ2Int(xChunk, zChunk);
|
||||
MapChunk property;
|
||||
|
||||
if (!chunkMapping.containsKey(chunkId)) {
|
||||
property = new MapChunk();
|
||||
chunkMapping.put(chunkId, property);
|
||||
} else {
|
||||
property = (MapChunk) chunkMapping.get(chunkId);
|
||||
}
|
||||
|
||||
property.set(x & 0xF, z & 0xF, val);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class MapChunk {
|
||||
|
||||
@NetworkData
|
||||
private BitSet property;
|
||||
|
||||
@NetworkData
|
||||
private boolean fullSet = false;
|
||||
|
||||
public MapChunk() {
|
||||
}
|
||||
|
||||
public boolean get(int xChunk, int 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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
111
common/buildcraft/core/ZoneChunk.java
Executable file
111
common/buildcraft/core/ZoneChunk.java
Executable file
|
@ -0,0 +1,111 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class ZoneChunk {
|
||||
|
||||
@NetworkData
|
||||
public BitSet property;
|
||||
|
||||
@NetworkData
|
||||
private boolean fullSet = false;
|
||||
|
||||
public ZoneChunk() {
|
||||
}
|
||||
|
||||
public boolean get(int xChunk, int zChunk) {
|
||||
if (fullSet) {
|
||||
return true;
|
||||
} else if (property == null) {
|
||||
return false;
|
||||
} else {
|
||||
return property.get(xChunk + zChunk * 16);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int xChunk, int zChunk, boolean value) {
|
||||
if (value) {
|
||||
if (fullSet) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (property == null) {
|
||||
property = new BitSet(16 * 16);
|
||||
}
|
||||
|
||||
property.set(xChunk + zChunk * 16, value);
|
||||
|
||||
if (property.cardinality() >= 16 * 16) {
|
||||
property = null;
|
||||
fullSet = true;
|
||||
}
|
||||
} else {
|
||||
if (fullSet) {
|
||||
property = new BitSet(16 * 16);
|
||||
property.flip(0, 16 * 16 - 1);
|
||||
} else if (property == null) {
|
||||
// Note - ZonePlan should usually destroy such chunks
|
||||
property = new BitSet(16 * 16);
|
||||
}
|
||||
|
||||
property.set(xChunk + zChunk * 16, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setBoolean("fullSet", fullSet);
|
||||
|
||||
if (property != null) {
|
||||
nbt.setByteArray("bits", property.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
fullSet = nbt.getBoolean("fullSet");
|
||||
|
||||
if (nbt.hasKey("bits")) {
|
||||
property = BitSet.valueOf(nbt.getByteArray("bits"));
|
||||
}
|
||||
}
|
||||
|
||||
public BlockIndex getRandomBlockIndex(Random rand) {
|
||||
int x, z;
|
||||
|
||||
if (fullSet) {
|
||||
x = rand.nextInt(16);
|
||||
z = rand.nextInt(16);
|
||||
} else {
|
||||
int bitId = rand.nextInt(property.cardinality());
|
||||
int bitPosition = property.nextSetBit(0);
|
||||
|
||||
while (bitId > 0) {
|
||||
bitId--;
|
||||
|
||||
bitPosition = property.nextSetBit(bitPosition);
|
||||
}
|
||||
|
||||
z = bitPosition / 16;
|
||||
x = bitPosition - 16 * z;
|
||||
}
|
||||
|
||||
return new BlockIndex(x, 0, z);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return !fullSet && property.isEmpty();
|
||||
}
|
||||
}
|
149
common/buildcraft/core/ZonePlan.java
Executable file
149
common/buildcraft/core/ZonePlan.java
Executable file
|
@ -0,0 +1,149 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
||||
public class ZonePlan implements IZone {
|
||||
|
||||
// TODO: This can exceed 32k of data. Generalize the slicing code used
|
||||
// in tiles.
|
||||
@NetworkData
|
||||
private HashMap<ChunkIndex, ZoneChunk> chunkMapping = new HashMap<ChunkIndex, ZoneChunk>();
|
||||
|
||||
public boolean get(int x, int z) {
|
||||
int xChunk = x >> 4;
|
||||
int zChunk = z >> 4;
|
||||
ChunkIndex chunkId = new ChunkIndex(xChunk, zChunk);
|
||||
ZoneChunk property;
|
||||
|
||||
if (!chunkMapping.containsKey(chunkId)) {
|
||||
return false;
|
||||
} else {
|
||||
property = chunkMapping.get(chunkId);
|
||||
return property.get(x & 0xF, z & 0xF);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int x, int z, boolean val) {
|
||||
int xChunk = x >> 4;
|
||||
int zChunk = z >> 4;
|
||||
ChunkIndex chunkId = new ChunkIndex(xChunk, zChunk);
|
||||
ZoneChunk property;
|
||||
|
||||
if (!chunkMapping.containsKey(chunkId)) {
|
||||
if (val) {
|
||||
property = new ZoneChunk();
|
||||
chunkMapping.put(chunkId, property);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
property = chunkMapping.get(chunkId);
|
||||
}
|
||||
|
||||
property.set(x & 0xF, z & 0xF, val);
|
||||
|
||||
if (property.isEmpty()) {
|
||||
chunkMapping.remove(chunkId);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for (Map.Entry<ChunkIndex, ZoneChunk> e : chunkMapping.entrySet()) {
|
||||
NBTTagCompound subNBT = new NBTTagCompound();
|
||||
e.getKey().writeToNBT(subNBT);
|
||||
e.getValue().writeToNBT(subNBT);
|
||||
list.appendTag(subNBT);
|
||||
}
|
||||
|
||||
nbt.setTag("chunkMapping", list);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
NBTTagList list = nbt.getTagList("chunkMapping", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
NBTTagCompound subNBT = list.getCompoundTagAt(i);
|
||||
|
||||
ChunkIndex id = new ChunkIndex();
|
||||
id.readFromNBT(subNBT);
|
||||
|
||||
ZoneChunk chunk = new ZoneChunk();
|
||||
chunk.readFromNBT(subNBT);
|
||||
|
||||
chunkMapping.put(id, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double distanceTo(BlockIndex index) {
|
||||
double maxSqrDistance = Double.MAX_VALUE;
|
||||
|
||||
for (Map.Entry<ChunkIndex, ZoneChunk> e : chunkMapping.entrySet()) {
|
||||
double cx = e.getKey().x << 4 + 8;
|
||||
double cz = e.getKey().x << 4 + 8;
|
||||
|
||||
double dx = cx - index.x;
|
||||
double dz = cz - index.z;
|
||||
|
||||
double sqrDistance = dx * dx + dz * dz;
|
||||
|
||||
if (sqrDistance < maxSqrDistance) {
|
||||
maxSqrDistance = sqrDistance;
|
||||
}
|
||||
}
|
||||
|
||||
return Math.sqrt(maxSqrDistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(double x, double y, double z) {
|
||||
int xBlock = (int) Math.floor(x);
|
||||
int zBlock = (int) Math.floor(z);
|
||||
|
||||
return get(xBlock, zBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockIndex getRandomBlockIndex(Random rand) {
|
||||
if (chunkMapping.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int chunkId = rand.nextInt(chunkMapping.size());
|
||||
|
||||
for (Map.Entry<ChunkIndex, ZoneChunk> e : chunkMapping.entrySet()) {
|
||||
if (chunkId == 0) {
|
||||
BlockIndex i = e.getValue().getRandomBlockIndex(rand);
|
||||
i.x = (e.getKey().x << 4) + i.x;
|
||||
i.z = (e.getKey().z << 4) + i.z;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
chunkId--;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ import net.minecraft.entity.item.EntityItem;
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.inventory.TransactorSimple;
|
||||
|
@ -28,7 +28,7 @@ public class AIRobotFetchItem extends AIRobot {
|
|||
private float maxRange;
|
||||
private IStackFilter stackFilter;
|
||||
private int pickTime = -1;
|
||||
private IBox box;
|
||||
private IZone zone;
|
||||
|
||||
private int targetToLoad = -1;
|
||||
|
||||
|
@ -36,12 +36,12 @@ public class AIRobotFetchItem extends AIRobot {
|
|||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotFetchItem(EntityRobotBase iRobot, float iMaxRange, IStackFilter iStackFilter, IBox iBox) {
|
||||
public AIRobotFetchItem(EntityRobotBase iRobot, float iMaxRange, IStackFilter iStackFilter, IZone iZone) {
|
||||
super(iRobot);
|
||||
|
||||
maxRange = iMaxRange;
|
||||
stackFilter = iStackFilter;
|
||||
box = iBox;
|
||||
zone = iZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,7 +114,7 @@ public class AIRobotFetchItem extends AIRobot {
|
|||
&& e instanceof EntityItem
|
||||
&& !BoardRobotPicker.targettedItems.contains(e.getEntityId())
|
||||
&& !robot.isKnownUnreachable(e)
|
||||
&& (box == null || box.contains(e.posX, e.posY, e.posZ))) {
|
||||
&& (zone == null || zone.contains(e.posX, e.posY, e.posZ))) {
|
||||
double dx = e.posX - robot.posX;
|
||||
double dy = e.posY - robot.posY;
|
||||
double dz = e.posZ - robot.posZ;
|
||||
|
|
|
@ -11,7 +11,7 @@ package buildcraft.core.robots;
|
|||
import java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.utils.PathFinding;
|
||||
|
@ -25,24 +25,24 @@ public class AIRobotGotoRandomGroundBlock extends AIRobot {
|
|||
private PathFinding pathFinding;
|
||||
private PathFindingJob pathFindingJob;
|
||||
private IBlockFilter filter;
|
||||
private IBox area;
|
||||
private IZone zone;
|
||||
|
||||
public AIRobotGotoRandomGroundBlock(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotGotoRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
|
||||
public AIRobotGotoRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IZone iZone) {
|
||||
super(iRobot);
|
||||
|
||||
range = iRange;
|
||||
filter = iFilter;
|
||||
area = iArea;
|
||||
zone = iZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (pathFindingJob == null) {
|
||||
startDelegateAI(new AIRobotSearchRandomGroundBlock(robot, range, filter, area));
|
||||
startDelegateAI(new AIRobotSearchRandomGroundBlock(robot, range, filter, zone));
|
||||
} else {
|
||||
if (!pathFindingJob.isAlive()) {
|
||||
LinkedList<BlockIndex> path = pathFinding.getResult();
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.inventory.ITransactor;
|
||||
|
@ -30,22 +30,22 @@ public class AIRobotGotoStationToLoad extends AIRobot {
|
|||
public boolean found = false;
|
||||
|
||||
private IStackFilter filter;
|
||||
private IBox box;
|
||||
private IZone zone;
|
||||
|
||||
public AIRobotGotoStationToLoad(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotGotoStationToLoad(EntityRobotBase iRobot, IStackFilter iFilter, IBox iBox) {
|
||||
public AIRobotGotoStationToLoad(EntityRobotBase iRobot, IStackFilter iFilter, IZone iZone) {
|
||||
super(iRobot);
|
||||
|
||||
filter = iFilter;
|
||||
box = iBox;
|
||||
zone = iZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(), box));
|
||||
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationFilter(), zone));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,8 +10,8 @@ package buildcraft.core.robots;
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.inventory.InventoryIterator;
|
||||
|
@ -24,22 +24,22 @@ public class AIRobotGotoStationToUnload extends AIRobot {
|
|||
|
||||
public boolean found = false;
|
||||
|
||||
private IBox box;
|
||||
private IZone zone;
|
||||
|
||||
public AIRobotGotoStationToUnload(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotGotoStationToUnload(EntityRobotBase iRobot, IBox iBox) {
|
||||
public AIRobotGotoStationToUnload(EntityRobotBase iRobot, IZone iZone) {
|
||||
super(iRobot);
|
||||
|
||||
box = iBox;
|
||||
zone = iZone;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationInventory(), box));
|
||||
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationInventory(), zone));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
package buildcraft.core.robots;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.DockingStationRegistry;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
|
@ -19,17 +19,17 @@ public class AIRobotSearchAndGotoStation extends AIRobot {
|
|||
|
||||
public DockingStation targetStation;
|
||||
private IStationFilter filter;
|
||||
private IBox box;
|
||||
private IZone zone;
|
||||
|
||||
public AIRobotSearchAndGotoStation(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotSearchAndGotoStation(EntityRobotBase iRobot, IStationFilter iFilter, IBox iBox) {
|
||||
public AIRobotSearchAndGotoStation(EntityRobotBase iRobot, IStationFilter iFilter, IZone iZone) {
|
||||
super(iRobot);
|
||||
|
||||
filter = iFilter;
|
||||
box = iBox;
|
||||
zone = iZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class AIRobotSearchAndGotoStation extends AIRobot {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (box != null && !box.contains(d.x(), d.y(), d.z())) {
|
||||
if (zone != null && !zone.contains(d.x(), d.y(), d.z())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class AIRobotSearchBlock extends AIRobot {
|
|||
|
||||
@Override
|
||||
public void start() {
|
||||
blockScanner = new PathFinding(robot.worldObj, new BlockIndex(robot), pathFound, 64, robot.getAreaToWork());
|
||||
blockScanner = new PathFinding(robot.worldObj, new BlockIndex(robot), pathFound, 64, robot.getZoneToWork());
|
||||
blockScannerJob = new PathFindingJob(blockScanner);
|
||||
blockScannerJob.start();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ package buildcraft.core.robots;
|
|||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.inventory.TransactorSimple;
|
||||
|
@ -20,18 +20,18 @@ public class AIRobotSearchEntity extends AIRobot {
|
|||
public Entity target;
|
||||
|
||||
private float maxRange;
|
||||
private IBox box;
|
||||
private IZone zone;
|
||||
private IEntityFilter filter;
|
||||
|
||||
public AIRobotSearchEntity(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotSearchEntity(EntityRobotBase iRobot, IEntityFilter iFilter, float iMaxRange, IBox iBox) {
|
||||
public AIRobotSearchEntity(EntityRobotBase iRobot, IEntityFilter iFilter, float iMaxRange, IZone iZone) {
|
||||
super(iRobot);
|
||||
|
||||
maxRange = iMaxRange;
|
||||
box = iBox;
|
||||
zone = iZone;
|
||||
filter = iFilter;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class AIRobotSearchEntity extends AIRobot {
|
|||
|
||||
if (!e.isDead
|
||||
&& filter.matches(e)
|
||||
&& (box == null || box.contains(e.posX, e.posY, e.posZ))
|
||||
&& (zone == null || zone.contains(e.posX, e.posY, e.posZ))
|
||||
&& (!robot.isKnownUnreachable(e))) {
|
||||
double dx = e.posX - robot.posX;
|
||||
double dy = e.posY - robot.posY;
|
||||
|
|
|
@ -9,10 +9,9 @@
|
|||
package buildcraft.core.robots;
|
||||
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.Box;
|
||||
|
||||
public class AIRobotSearchRandomGroundBlock extends AIRobot {
|
||||
|
||||
|
@ -22,19 +21,19 @@ public class AIRobotSearchRandomGroundBlock extends AIRobot {
|
|||
|
||||
private int range;
|
||||
private IBlockFilter filter;
|
||||
private IBox area;
|
||||
private IZone zone;
|
||||
private int attempts = 0;
|
||||
|
||||
public AIRobotSearchRandomGroundBlock(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotSearchRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IBox iArea) {
|
||||
public AIRobotSearchRandomGroundBlock(EntityRobotBase iRobot, int iRange, IBlockFilter iFilter, IZone iZone) {
|
||||
super(iRobot);
|
||||
|
||||
range = iRange;
|
||||
filter = iFilter;
|
||||
area = iArea;
|
||||
zone = iZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,15 +52,16 @@ public class AIRobotSearchRandomGroundBlock extends AIRobot {
|
|||
int x = 0;
|
||||
int z = 0;
|
||||
|
||||
if (area == null) {
|
||||
if (zone == null) {
|
||||
double r = robot.worldObj.rand.nextFloat() * range;
|
||||
double a = robot.worldObj.rand.nextFloat() * 2.0 * Math.PI;
|
||||
|
||||
x = (int) (Math.cos(a) * r + Math.floor(robot.posX));
|
||||
z = (int) (Math.sin(a) * r + Math.floor(robot.posZ));
|
||||
} else {
|
||||
x = (int) area.pMin().x + robot.worldObj.rand.nextInt(((Box) area).sizeX());
|
||||
z = (int) area.pMin().z + robot.worldObj.rand.nextInt(((Box) area).sizeZ());
|
||||
BlockIndex b = zone.getRandomBlockIndex(robot.worldObj.rand);
|
||||
x = b.x;
|
||||
z = b.z;
|
||||
}
|
||||
|
||||
for (int y = robot.worldObj.getHeight(); y >= 0; --y) {
|
||||
|
|
|
@ -33,7 +33,7 @@ import buildcraft.api.boards.RedstoneBoardNBT;
|
|||
import buildcraft.api.boards.RedstoneBoardRegistry;
|
||||
import buildcraft.api.boards.RedstoneBoardRobot;
|
||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.mj.MjBattery;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
|
@ -728,14 +728,14 @@ public class EntityRobot extends EntityRobotBase implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public IBox getAreaToWork() {
|
||||
public IZone getZoneToWork() {
|
||||
if (linkedDockingStation instanceof DockingStation) {
|
||||
for (ActionSlot s : new ActionIterator(((DockingStation) linkedDockingStation).pipe.pipe)) {
|
||||
if (s.action instanceof ActionRobotWorkInArea) {
|
||||
IBox box = ActionRobotWorkInArea.getArea(s);
|
||||
IZone zone = ActionRobotWorkInArea.getArea(s);
|
||||
|
||||
if (box != null) {
|
||||
return box;
|
||||
if (zone != null) {
|
||||
return zone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class BoardRobotBomber extends RedstoneBoardRobot {
|
|||
public boolean matches(World world, int x, int y, int z) {
|
||||
return y < world.getActualHeight() - flyingHeight && !world.isAirBlock(x, y, z);
|
||||
}
|
||||
}, robot.getAreaToWork()));
|
||||
}, robot.getZoneToWork()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public class BoardRobotBuilder extends RedstoneBoardRobot {
|
|||
if (requirementsToLookFor != null && requirementsToLookFor.size() > 0) {
|
||||
startDelegateAI(new AIRobotGotoStationToLoad(robot,
|
||||
new ArrayStackFilter(requirementsToLookFor.getFirst()),
|
||||
robot.getAreaToWork()));
|
||||
robot.getZoneToWork()));
|
||||
}
|
||||
|
||||
if (currentBuildingSlot != null && requirementsToLookFor != null && requirementsToLookFor.size() == 0) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class BoardRobotButcher extends RedstoneBoardRobot {
|
|||
public boolean matches(Entity entity) {
|
||||
return entity instanceof EntityAnimal;
|
||||
}
|
||||
}, 250, robot.getAreaToWork()));
|
||||
}, 250, robot.getZoneToWork()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@ public class BoardRobotCarrier extends RedstoneBoardRobot {
|
|||
public void update() {
|
||||
if (!robot.containsItems()) {
|
||||
startDelegateAI(new AIRobotGotoStationToLoad(robot, ActionRobotFilter.getGateFilter(robot
|
||||
.getLinkedStation()), robot.getAreaToWork()));
|
||||
.getLinkedStation()), robot.getZoneToWork()));
|
||||
} else {
|
||||
startDelegateAI(new AIRobotGotoStationToUnload(robot, robot.getAreaToWork()));
|
||||
startDelegateAI(new AIRobotGotoStationToUnload(robot, robot.getZoneToWork()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class BoardRobotCarrier extends RedstoneBoardRobot {
|
|||
loadFound = false;
|
||||
|
||||
if (robot.containsItems()) {
|
||||
startDelegateAI(new AIRobotGotoStationToUnload(robot, robot.getAreaToWork()));
|
||||
startDelegateAI(new AIRobotGotoStationToUnload(robot, robot.getZoneToWork()));
|
||||
} else {
|
||||
unloadFound = false;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class BoardRobotCarrier extends RedstoneBoardRobot {
|
|||
} else {
|
||||
unloadFound = false;
|
||||
startDelegateAI(new AIRobotGotoStationToLoad(robot, ActionRobotFilter.getGateFilter(robot
|
||||
.getLinkedStation()), robot.getAreaToWork()));
|
||||
.getLinkedStation()), robot.getZoneToWork()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class BoardRobotKnight extends RedstoneBoardRobot {
|
|||
public boolean matches(Entity entity) {
|
||||
return entity instanceof EntityMob;
|
||||
}
|
||||
}, 250, robot.getAreaToWork()));
|
||||
}, 250, robot.getZoneToWork()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
@Override
|
||||
public void update() {
|
||||
startDelegateAI(new AIRobotFetchItem(robot, range, ActionRobotFilter.getGateFilter(robot
|
||||
.getLinkedStation()), robot.getAreaToWork()));
|
||||
.getLinkedStation()), robot.getZoneToWork()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +60,7 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
|
|||
// if we find an item - that may have been cancelled.
|
||||
// let's try to get another one
|
||||
startDelegateAI(new AIRobotFetchItem(robot, range, ActionRobotFilter.getGateFilter(robot
|
||||
.getLinkedStation()), robot.getAreaToWork()));
|
||||
.getLinkedStation()), robot.getZoneToWork()));
|
||||
} else if (robot.containsItems()) {
|
||||
startDelegateAI(new AIRobotGotoStationToUnload(robot, null));
|
||||
} else {
|
||||
|
|
|
@ -97,7 +97,7 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
|
|||
|
||||
return b instanceof BlockDirt || b instanceof BlockGrass;
|
||||
}
|
||||
}, robot.getAreaToWork()));
|
||||
}, robot.getZoneToWork()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import net.minecraft.world.World;
|
|||
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.core.robots.IBlockFilter;
|
||||
|
||||
/**
|
||||
|
@ -36,8 +36,7 @@ public class PathFinding {
|
|||
private IBlockFilter pathFound;
|
||||
private float maxDistance = -1;
|
||||
private float sqrMaxDistance = -1;
|
||||
private IBox box;
|
||||
private BlockIndex boxCenter;
|
||||
private IZone zone;
|
||||
private double maxDistanceToEnd = 0;
|
||||
|
||||
private HashMap<BlockIndex, Node> openList = new HashMap<BlockIndex, PathFinding.Node>();
|
||||
|
@ -70,7 +69,7 @@ public class PathFinding {
|
|||
maxDistanceToEnd = iMaxDistanceToEnd;
|
||||
}
|
||||
|
||||
public PathFinding(World iWorld, BlockIndex iStart, IBlockFilter iPathFound, float iMaxDistance, IBox iBox) {
|
||||
public PathFinding(World iWorld, BlockIndex iStart, IBlockFilter iPathFound, float iMaxDistance, IZone iZone) {
|
||||
world = iWorld;
|
||||
start = iStart;
|
||||
pathFound = iPathFound;
|
||||
|
@ -85,14 +84,7 @@ public class PathFinding {
|
|||
nextIteration = startNode;
|
||||
maxDistance = iMaxDistance;
|
||||
sqrMaxDistance = maxDistance * maxDistance;
|
||||
box = iBox;
|
||||
|
||||
if (box != null) {
|
||||
boxCenter = new BlockIndex();
|
||||
boxCenter.x = (int) (box.pMin().x + (box.pMax().x - box.pMin().x) / 2);
|
||||
boxCenter.y = (int) (box.pMin().y + (box.pMax().y - box.pMin().y) / 2);
|
||||
boxCenter.z = (int) (box.pMin().z + (box.pMax().z - box.pMin().z) / 2);
|
||||
}
|
||||
zone = iZone;
|
||||
}
|
||||
|
||||
public void iterate() {
|
||||
|
@ -163,11 +155,11 @@ public class PathFinding {
|
|||
|
||||
if (end != null) {
|
||||
nextNode.destinationCost = distance(nextNode.index, end);
|
||||
} else if (box != null) {
|
||||
if (box.contains(x, y, z)) {
|
||||
} else if (zone != null) {
|
||||
if (zone.contains(x, y, z)) {
|
||||
nextNode.destinationCost = 0;
|
||||
} else {
|
||||
nextNode.destinationCost = distance(nextNode.index, boxCenter);
|
||||
nextNode.destinationCost = zone.distanceTo(nextNode.index);
|
||||
}
|
||||
} else {
|
||||
nextNode.destinationCost = 0;
|
||||
|
@ -230,7 +222,7 @@ public class PathFinding {
|
|||
}
|
||||
|
||||
private boolean endReached(int x, int y, int z) {
|
||||
if (box != null && !box.contains(x, y, z)) {
|
||||
if (zone != null && !zone.contains(x, y, z)) {
|
||||
return false;
|
||||
} else if (pathFound != null) {
|
||||
return pathFound.matches(world, x, y, z);
|
||||
|
|
|
@ -11,7 +11,7 @@ package buildcraft.silicon.statements;
|
|||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.IZone;
|
||||
import buildcraft.api.gates.ActionParameterItemStack;
|
||||
import buildcraft.api.gates.IActionParameter;
|
||||
import buildcraft.core.ItemMapLocation;
|
||||
|
@ -35,7 +35,7 @@ public class ActionRobotWorkInArea extends BCActionPassive {
|
|||
icon = iconRegister.registerIcon("buildcraft:triggers/action_robot_in_area");
|
||||
}
|
||||
|
||||
public static IBox getArea(ActionSlot slot) {
|
||||
public static IZone getArea(ActionSlot slot) {
|
||||
if (slot.parameters[0] == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class ActionRobotWorkInArea extends BCActionPassive {
|
|||
return null;
|
||||
}
|
||||
|
||||
return ItemMapLocation.getBox(stack);
|
||||
return ItemMapLocation.getZone(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue