Revert Builder changes
I don't know how these got merged, but they shouldn't have been.
This commit is contained in:
parent
eecc8ebf36
commit
b44d60f4fe
13 changed files with 193 additions and 1113 deletions
|
@ -12,7 +12,6 @@ package buildcraft;
|
|||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.api.core.IIconProvider;
|
||||
import buildcraft.api.gates.ActionManager;
|
||||
import buildcraft.builders.blueprints.BlueprintDatabase;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.BlockSpring;
|
||||
import buildcraft.core.BuildCraftConfiguration;
|
||||
|
@ -173,7 +172,6 @@ public class BuildCraftCore {
|
|||
bcLog.info("Copyright (c) SpaceToad, 2011");
|
||||
bcLog.info("http://www.mod-buildcraft.com");
|
||||
|
||||
BlueprintDatabase.configFolder = evt.getModConfigurationDirectory();
|
||||
mainConfiguration = new BuildCraftConfiguration(new File(evt.getModConfigurationDirectory(), "buildcraft/main.conf"));
|
||||
try {
|
||||
mainConfiguration.load();
|
||||
|
|
|
@ -1,221 +0,0 @@
|
|||
package buildcraft.api.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* BlockHandlers are used to serialize blocks for saving/loading from
|
||||
* Blueprints.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class BlockHandler {
|
||||
|
||||
private static final Map<Integer, BlockHandler> handlers = new HashMap<Integer, BlockHandler>();
|
||||
private final int id;
|
||||
|
||||
public static BlockHandler get(Item item) {
|
||||
if (item == null)
|
||||
return null;
|
||||
return get(item.itemID);
|
||||
}
|
||||
|
||||
public static BlockHandler get(Block block) {
|
||||
if (block == null)
|
||||
return null;
|
||||
return get(block.blockID);
|
||||
}
|
||||
|
||||
public static BlockHandler get(int id) {
|
||||
BlockHandler handler = handlers.get(id);
|
||||
if (handler == null) {
|
||||
handler = new BlockHandler(id);
|
||||
registerHandler(id, handler);
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
public static void registerHandler(Block block, BlockHandler handler) {
|
||||
handlers.put(block.blockID, handler);
|
||||
}
|
||||
|
||||
public static void registerHandler(Item item, BlockHandler handler) {
|
||||
handlers.put(item.itemID, handler);
|
||||
}
|
||||
|
||||
public static void registerHandler(int id, BlockHandler handler) {
|
||||
handlers.put(id, handler);
|
||||
}
|
||||
|
||||
public BlockHandler(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* By default we will ignore all blocks with Tile Entities.
|
||||
*
|
||||
* We will also skip any blocks that drop actual items like Ore blocks.
|
||||
*/
|
||||
public boolean canSaveToSchematic(World world, int x, int y, int z) {
|
||||
if (!(Item.itemsList[id] instanceof ItemBlock))
|
||||
return false;
|
||||
|
||||
Block block = Block.blocksList[id];
|
||||
if (block == null)
|
||||
return false;
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
try {
|
||||
if (block.idDropped(meta, null, 0) != id)
|
||||
return false;
|
||||
|
||||
} catch (NullPointerException ex) {
|
||||
return false;
|
||||
}
|
||||
return !block.hasTileEntity(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* By default we will ignore all blocks with Tile Entities.
|
||||
*
|
||||
* We will also ignore anything that's not a ItemBlock.
|
||||
*
|
||||
* We will also skip any blocks that drop actual items like Ore blocks.
|
||||
*/
|
||||
public boolean canSaveToSchematic(ItemStack stack) {
|
||||
if (stack == null)
|
||||
return false;
|
||||
if (!(stack.getItem() instanceof ItemBlock))
|
||||
return false;
|
||||
|
||||
if (id > Block.blocksList.length)
|
||||
return false;
|
||||
|
||||
Block block = Block.blocksList[id];
|
||||
if (block == null)
|
||||
return false;
|
||||
|
||||
try {
|
||||
if (block.idDropped(stack.getItemDamage(), null, 0) != id)
|
||||
return false;
|
||||
} catch (NullPointerException ex) {
|
||||
return false;
|
||||
}
|
||||
return !block.hasTileEntity(stack.getItemDamage());
|
||||
}
|
||||
|
||||
/**
|
||||
* It is assumed that Blueprints always face North on save.
|
||||
*
|
||||
* Store any info you need to reproduce the block in the data tag.
|
||||
*/
|
||||
public void saveToSchematic(World world, int x, int y, int z, NBTTagCompound data) {
|
||||
data.setByte("blockMeta", (byte) world.getBlockMetadata(x, y, z));
|
||||
}
|
||||
|
||||
/**
|
||||
* It is assumed that Blueprints always face North on save.
|
||||
*
|
||||
* Store any info you need to reproduce the block from this ItemStack in the
|
||||
* data tag.
|
||||
*/
|
||||
public void saveToSchematic(ItemStack stack, NBTTagCompound data) {
|
||||
if (stack.getHasSubtypes())
|
||||
data.setByte("blockMeta", (byte) stack.getItemDamage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a list of all the items that must be present to build this
|
||||
* schematic.
|
||||
*
|
||||
* If you need axillary items like a painter or gate, list them as well.
|
||||
* Items will be consumed in the readBlockFromSchematic() function below.
|
||||
*
|
||||
* This default implementation will only work for simple blocks without tile
|
||||
* entities and will in fact break on Ore blocks as well. Which is why those
|
||||
* blocks can't be saved by default.
|
||||
*/
|
||||
public List<ItemStack> getCostForSchematic(NBTTagCompound data) {
|
||||
List<ItemStack> cost = new ArrayList<ItemStack>();
|
||||
Block block = Block.blocksList[id];
|
||||
cost.add(new ItemStack(block.idDropped(data.getByte("blockMeta"), BlueprintHelpers.RANDOM, 0), 1, block.damageDropped(data.getByte("blockMeta"))));
|
||||
return cost;
|
||||
}
|
||||
|
||||
private boolean areItemsEqual(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null || stack2 == null)
|
||||
return false;
|
||||
if (!stack1.isItemEqual(stack2))
|
||||
return false;
|
||||
if (!ItemStack.areItemStackTagsEqual(stack1, stack2))
|
||||
return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the block be placed currently or is it waiting on some other block to
|
||||
* be placed first?
|
||||
*/
|
||||
public boolean canPlaceNow(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function handles the placement of the block in the world.
|
||||
*
|
||||
* The ForgeDirection parameter can be use to determine the orientation of
|
||||
* the blueprint. Blueprints are always saved facing North. This function
|
||||
* will have to rotate the block accordingly.
|
||||
*
|
||||
* The builder's inventory is passed in so you can consume the items you
|
||||
* need. Use them as you see fit.
|
||||
*
|
||||
* If the function returns false, the block was not placed. You should not
|
||||
* modify any ItemStack in the inventory until you have determined that
|
||||
* everything you require is present.
|
||||
*/
|
||||
public boolean readBlockFromSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound data, IInventory builderInventory, EntityPlayer bcPlayer) {
|
||||
if (builderInventory != null) {
|
||||
List<ItemStack> requiredItems = getCostForSchematic(data);
|
||||
List<Integer> slotsToConsume = new ArrayList<Integer>();
|
||||
for (ItemStack cost : requiredItems) {
|
||||
boolean found = false;
|
||||
for (int slot = 0; slot < builderInventory.getSizeInventory(); slot++) {
|
||||
if (areItemsEqual(builderInventory.getStackInSlot(slot), cost)) {
|
||||
slotsToConsume.add(slot);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
return false;
|
||||
}
|
||||
for (Integer slot : slotsToConsume) {
|
||||
builderInventory.setInventorySlotContents(slot, BlueprintHelpers.consumeItem(builderInventory.getStackInSlot(slot)));
|
||||
}
|
||||
}
|
||||
return world.setBlock(x, y, z, Block.blocksList[id].blockID, data.getByte("blockMeta"), 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the block matches the schematic.
|
||||
*/
|
||||
public boolean doesBlockMatchSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound data) {
|
||||
if (id != world.getBlockId(x, y, z))
|
||||
return false;
|
||||
|
||||
return !data.hasKey("blockMeta") || data.getByte("blockMeta") == world.getBlockMetadata(x, y, z);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package buildcraft.api.builder;
|
||||
|
||||
import java.util.Random;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class BlueprintHelpers {
|
||||
|
||||
public static final Random RANDOM = new Random();
|
||||
|
||||
/**
|
||||
* Takes a schematic orientation and blueprint orientation and returns the
|
||||
* orientation that should be used in the world. Admittedly this is not
|
||||
* sufficient for 24-point rotation. If you need something more complex, you
|
||||
* will have to handle it yourself.
|
||||
*/
|
||||
public static ForgeDirection rotateOrientation(ForgeDirection schematicOrientation, ForgeDirection blueprintOrientation) {
|
||||
if (schematicOrientation == ForgeDirection.UP || schematicOrientation == ForgeDirection.DOWN) {
|
||||
return schematicOrientation;
|
||||
}
|
||||
if (blueprintOrientation == ForgeDirection.SOUTH) {
|
||||
return schematicOrientation.getOpposite();
|
||||
}
|
||||
if (blueprintOrientation == ForgeDirection.WEST) {
|
||||
return schematicOrientation.getRotation(ForgeDirection.DOWN);
|
||||
}
|
||||
if (blueprintOrientation == ForgeDirection.EAST) {
|
||||
return schematicOrientation.getRotation(ForgeDirection.UP);
|
||||
}
|
||||
return schematicOrientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an ItemStack and uses one. Replaces containers as needed.
|
||||
*
|
||||
* @return the new ItemStack
|
||||
*/
|
||||
public static ItemStack consumeItem(ItemStack stack) {
|
||||
if (stack.stackSize == 1) {
|
||||
if (stack.getItem().hasContainerItem()) {
|
||||
return stack.getItem().getContainerItemStack(stack);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
stack.splitStack(1);
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,52 +1,47 @@
|
|||
/**
|
||||
<<<<<<< HEAD
|
||||
* Copyright (c) SpaceToad, 2011 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
|
||||
=======
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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
|
||||
>>>>>>> mc16
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.builders;
|
||||
|
||||
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.core.IAreaProvider;
|
||||
import buildcraft.api.core.LaserKind;
|
||||
import buildcraft.builders.blueprints.Blueprint;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.blueprints.BptBase;
|
||||
import buildcraft.core.blueprints.BptBlueprint;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.network.TileNetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.core.IAreaProvider;
|
||||
import buildcraft.api.core.LaserKind;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.blueprints.BptBase;
|
||||
import buildcraft.core.blueprints.BptBlueprint;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.blueprints.BptTemplate;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.network.TileNetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public class TileArchitect extends TileBuildCraft implements IInventory {
|
||||
|
||||
public @TileNetworkData
|
||||
Box box = new Box();
|
||||
|
||||
private ItemStack items[] = new ItemStack[2];
|
||||
|
||||
private boolean isComputing = false;
|
||||
public int computingTime = 0;
|
||||
|
||||
public @TileNetworkData
|
||||
String name = "";
|
||||
|
||||
// Use that field to avoid creating several times the same template if
|
||||
// they're the same!
|
||||
private int lastBptId = 0;
|
||||
|
@ -146,23 +141,21 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
|
|||
mask0 = 1;
|
||||
}
|
||||
|
||||
Blueprint blueprint = new Blueprint(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
BptBase result = new BptTemplate(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
|
||||
for (int x = box.xMin; x <= box.xMax; ++x) {
|
||||
for (int y = box.yMin; y <= box.yMax; ++y) {
|
||||
for (int z = box.zMin; z <= box.zMax; ++z) {
|
||||
if (!worldObj.isAirBlock(x, y, z)) {
|
||||
Block block = Block.blocksList[worldObj.getBlockId(x, y, z)];
|
||||
if (block != null) {
|
||||
blueprint.setSchematic(x - box.xMin, y - box.yMin, z - box.zMin, worldObj, block);
|
||||
}
|
||||
if (worldObj.getBlockId(x, y, z) != 0) {
|
||||
result.setBlockId(x - box.xMin, y - box.yMin, z - box.zMin, mask1);
|
||||
} else {
|
||||
result.setBlockId(x - box.xMin, y - box.yMin, z - box.zMin, mask0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return blueprint;
|
||||
return null;
|
||||
return result;
|
||||
}
|
||||
|
||||
private BptBase createBptBlueprint() {
|
||||
|
@ -373,9 +366,11 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
|
|||
|
||||
@Override
|
||||
public void openChest() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package buildcraft.builders.blueprints;
|
||||
|
||||
import buildcraft.api.builder.BlockHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public final class BlockSchematic extends Schematic {
|
||||
|
||||
public static BlockSchematic create(NBTTagCompound nbt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BlockSchematic create(Block block) {
|
||||
return new BlockSchematic(block);
|
||||
}
|
||||
public final Block block;
|
||||
|
||||
private BlockSchematic(Block block) {
|
||||
super(block.blockID);
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
private BlockSchematic(String nbt) {
|
||||
// String blockName = nbt.getString("blockName");
|
||||
this((Block) null); // TODO: Add block from name code
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockHandler getHandler() {
|
||||
return BlockHandler.get(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setString("schematicType", "block");
|
||||
nbt.setString("blockName", block.getUnlocalizedName());
|
||||
}
|
||||
}
|
|
@ -1,241 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011-2012 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.builders.blueprints;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.builder.BlockHandler;
|
||||
import buildcraft.core.inventory.StackHelper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* This class is used to represent the data of the blueprint as it exists in the
|
||||
* world.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class Blueprint {
|
||||
|
||||
private final String version = "Blueprint-2.0";
|
||||
private final UUID uuid;
|
||||
private String name;
|
||||
private String creator;
|
||||
private final Schematic[][][] schematics;
|
||||
public final int sizeX, sizeY, sizeZ;
|
||||
public int anchorX, anchorY, anchorZ;
|
||||
public ForgeDirection anchorOrientation = ForgeDirection.NORTH;
|
||||
private List<ItemStack> costs;
|
||||
|
||||
public Blueprint(int sizeX, int sizeY, int sizeZ) {
|
||||
this(sizeX, sizeY, sizeZ, UUID.randomUUID());
|
||||
}
|
||||
|
||||
private Blueprint(int sizeX, int sizeY, int sizeZ, UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
this.sizeX = sizeX;
|
||||
this.sizeY = sizeY;
|
||||
this.sizeZ = sizeZ;
|
||||
schematics = new Schematic[sizeX][sizeY][sizeZ];
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private void setSchematic(int x, int y, int z, Schematic schematic) {
|
||||
if (schematic == null)
|
||||
return;
|
||||
schematic.x = x;
|
||||
schematic.y = y;
|
||||
schematic.z = z;
|
||||
schematics[x][y][z] = schematic;
|
||||
}
|
||||
|
||||
public void setSchematic(int x, int y, int z, World world, Block block) {
|
||||
BlockHandler handler = BlockHandler.get(block);
|
||||
try {
|
||||
if (handler.canSaveToSchematic(world, x, y, z)) {
|
||||
Schematic schematic = BlockSchematic.create(block);
|
||||
handler.saveToSchematic(world, x, y, z, schematic.data);
|
||||
setSchematic(x, y, z, schematic);
|
||||
}
|
||||
} catch (Throwable error) {
|
||||
BuildCraftCore.bcLog.severe(String.format("Error while trying to save block [%s:%d] to blueprint, skipping.", block.getUnlocalizedName(), block.blockID));
|
||||
BuildCraftCore.bcLog.throwing(getClass().getCanonicalName(), "setBlock", error);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSchematic(int x, int y, int z, ItemStack item) {
|
||||
if (item == null)
|
||||
return;
|
||||
BlockHandler handler = BlockHandler.get(item.getItem());
|
||||
try {
|
||||
if (handler.canSaveToSchematic(item)) {
|
||||
Schematic schematic = ItemSchematic.create(item.getItem());
|
||||
handler.saveToSchematic(item, schematic.data);
|
||||
setSchematic(x, y, z, schematic);
|
||||
}
|
||||
} catch (Throwable error) {
|
||||
BuildCraftCore.bcLog.severe(String.format("Error while trying to save item [%s:%d] to blueprint, skipping.", item.getItem().getUnlocalizedName(), item.itemID));
|
||||
BuildCraftCore.bcLog.throwing(getClass().getCanonicalName(), "setBlock", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for creating Blueprints in code.
|
||||
*
|
||||
* Not recommended for use with complex blocks because it doesn't go through
|
||||
* a hander to get a BlockSchematic.
|
||||
*
|
||||
* @see TileQuarry
|
||||
*/
|
||||
public void setSchematic(World world, int x, int y, int z, int id, int meta) {
|
||||
Block block = Block.blocksList[id];
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
BlockSchematic schematic = BlockSchematic.create(block);
|
||||
schematic.data.setByte("blockMeta", (byte) meta);
|
||||
setSchematic(x, y, z, schematic);
|
||||
}
|
||||
|
||||
public Schematic getBlock(int x, int y, int z) {
|
||||
return schematics[x][y][z];
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all blocks in the Blueprint in the order they should be
|
||||
* built.
|
||||
*
|
||||
* Be aware that changes to the Blueprint will not propagate to the list nor
|
||||
* will changes to the list propagate to the Blueprint.
|
||||
*
|
||||
* @return List<BlockScematic>
|
||||
*/
|
||||
public LinkedList<Schematic> getBuildList() {
|
||||
LinkedList<Schematic> list = new LinkedList<Schematic>();
|
||||
for (int y = 0; y < sizeY; y++) {
|
||||
for (int x = 0; x < sizeX; x++) {
|
||||
for (int z = 0; z < sizeZ; z++) {
|
||||
if (schematics[x][y][z] != null)
|
||||
list.add(schematics[x][y][z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ItemStack> getCost() {
|
||||
if (costs != null)
|
||||
return costs;
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
for (Schematic schematic : getBuildList()) {
|
||||
BlockHandler handler = BlockHandler.get(schematic.id);
|
||||
List<ItemStack> requirements = handler.getCostForSchematic(schematic.data);
|
||||
for (ItemStack newStack : requirements) {
|
||||
if (newStack.stackSize <= 0)
|
||||
continue;
|
||||
for (ItemStack oldStack : stacks) {
|
||||
if (StackHelper.instance().canStacksMerge(oldStack, newStack)) {
|
||||
newStack.stackSize -= StackHelper.instance().mergeStacks(oldStack, newStack, true);
|
||||
}
|
||||
}
|
||||
if (newStack.stackSize > 0)
|
||||
stacks.add(newStack);
|
||||
}
|
||||
}
|
||||
costs = Collections.unmodifiableList(stacks);
|
||||
return costs;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagList blockList = new NBTTagList();
|
||||
for (int y = 0; y < sizeY; y++) {
|
||||
for (int x = 0; x < sizeX; x++) {
|
||||
for (int z = 0; z < sizeZ; z++) {
|
||||
if (schematics[x][y][z] == null)
|
||||
continue;
|
||||
NBTTagCompound blockNBT = new NBTTagCompound();
|
||||
schematics[x][y][z].writeToNBT(nbt);
|
||||
blockList.appendTag(blockNBT);
|
||||
}
|
||||
}
|
||||
}
|
||||
nbt.setTag("blocks", blockList);
|
||||
nbt.setLong("uuidMost", uuid.getMostSignificantBits());
|
||||
nbt.setLong("uuidLeast", uuid.getLeastSignificantBits());
|
||||
nbt.setString("name", name);
|
||||
nbt.setString("version", version);
|
||||
nbt.setString("creator", creator);
|
||||
nbt.setInteger("sizeX", sizeX);
|
||||
nbt.setInteger("sizeY", sizeY);
|
||||
nbt.setInteger("sizeZ", sizeZ);
|
||||
nbt.setInteger("anchorX", sizeX);
|
||||
nbt.setInteger("anchorY", sizeY);
|
||||
nbt.setInteger("anchorZ", sizeZ);
|
||||
nbt.setByte("anchorOrientation", (byte) anchorOrientation.ordinal());
|
||||
}
|
||||
|
||||
public static Blueprint readFromNBT(NBTTagCompound nbt) {
|
||||
long most = nbt.getLong("uuidMost");
|
||||
long least = nbt.getLong("uuidLeast");
|
||||
int sizeX = nbt.getInteger("sizeX");
|
||||
int sizeY = nbt.getInteger("sizeY");
|
||||
int sizeZ = nbt.getInteger("sizeZ");
|
||||
|
||||
Blueprint blueprint = new Blueprint(sizeX, sizeY, sizeZ, new UUID(most, least));
|
||||
|
||||
blueprint.name = nbt.getString("name");
|
||||
blueprint.creator = nbt.getString("creator");
|
||||
|
||||
blueprint.anchorX = nbt.getInteger("anchorX");
|
||||
blueprint.anchorY = nbt.getInteger("anchorY");
|
||||
blueprint.anchorZ = nbt.getInteger("anchorZ");
|
||||
|
||||
blueprint.anchorOrientation = ForgeDirection.getOrientation(nbt.getByte("anchorOrientation"));
|
||||
|
||||
NBTTagList blockList = nbt.getTagList("blocks");
|
||||
for (int i = 0; i < blockList.tagCount(); i++) {
|
||||
NBTTagCompound blockNBT = (NBTTagCompound) blockList.tagAt(i);
|
||||
Schematic schematic = Schematic.createSchematicFromNBT(blockNBT);
|
||||
blueprint.schematics[schematic.x][schematic.y][schematic.z] = schematic;
|
||||
}
|
||||
return blueprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the creator
|
||||
*/
|
||||
public String getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param creator the creator to set
|
||||
*/
|
||||
public void setCreator(String creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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.builders.blueprints;
|
||||
|
||||
import buildcraft.api.builder.BlockHandler;
|
||||
import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import static net.minecraftforge.common.ForgeDirection.EAST;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class BlueprintBuilder {
|
||||
|
||||
public final Blueprint blueprint;
|
||||
public final ForgeDirection orientation;
|
||||
public final World worldObj;
|
||||
public final int x, y, z;
|
||||
private final IInventory inv;
|
||||
private final LinkedList<Schematic> buildList;
|
||||
private final List<SchematicBuilder> builders;
|
||||
|
||||
public BlueprintBuilder(Blueprint blueprint, World world, int x, int y, int z, ForgeDirection orientation, IInventory inv) {
|
||||
this.blueprint = blueprint;
|
||||
this.orientation = orientation;
|
||||
this.worldObj = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.inv = inv;
|
||||
this.buildList = blueprint.getBuildList();
|
||||
builders = new ArrayList<SchematicBuilder>(buildList.size());
|
||||
for (Schematic schematic : buildList) {
|
||||
BlockHandler handler = schematic.getHandler();
|
||||
if (handler != null)
|
||||
builders.add(new SchematicBuilder(schematic, handler));
|
||||
}
|
||||
}
|
||||
|
||||
public List<SchematicBuilder> getBuilders() {
|
||||
return Collections.unmodifiableList(builders);
|
||||
}
|
||||
|
||||
public class SchematicBuilder {
|
||||
|
||||
public final Schematic schematic;
|
||||
public final BlockHandler handler;
|
||||
private boolean complete;
|
||||
|
||||
private SchematicBuilder(Schematic schematic, BlockHandler handler) {
|
||||
this.schematic = schematic;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
switch (orientation) {
|
||||
case SOUTH:
|
||||
return x - schematic.x;
|
||||
case EAST:
|
||||
return x - schematic.z;
|
||||
case WEST:
|
||||
return x + schematic.z;
|
||||
default:
|
||||
return x + schematic.x;
|
||||
}
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y + schematic.y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
switch (orientation) {
|
||||
case SOUTH:
|
||||
return z - schematic.z;
|
||||
case EAST:
|
||||
return z + schematic.x;
|
||||
case WEST:
|
||||
return z - schematic.x;
|
||||
default:
|
||||
return z + schematic.z;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean blockExists() {
|
||||
return handler.doesBlockMatchSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.data);
|
||||
}
|
||||
|
||||
public boolean canBuild() {
|
||||
return handler.canPlaceNow(worldObj, getX(), getY(), getZ(), orientation, schematic.data);
|
||||
}
|
||||
|
||||
public boolean build(EntityPlayer bcPlayer) {
|
||||
// if (blockExists()) {
|
||||
// markComplete();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if (!BlockUtil.canChangeBlock(worldObj, getX(), getY(), getZ()))
|
||||
// return false;
|
||||
|
||||
if (!canBuild())
|
||||
return false;
|
||||
|
||||
boolean built = handler.readBlockFromSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.data, inv, bcPlayer);
|
||||
|
||||
if (built) {
|
||||
markComplete();
|
||||
}
|
||||
|
||||
return built;
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return complete;
|
||||
}
|
||||
|
||||
public void markComplete() {
|
||||
complete = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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.builders.blueprints;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class BlueprintDatabase {
|
||||
|
||||
public static File configFolder;
|
||||
private static Map<UUID, Blueprint> blueprints = new HashMap<UUID, Blueprint>();
|
||||
|
||||
public static Blueprint getBlueprint(UUID uuid) {
|
||||
Blueprint blueprint = blueprints.get(uuid);
|
||||
if (blueprint == null) {
|
||||
blueprint = loadBlueprint(uuid);
|
||||
addBlueprint(blueprint);
|
||||
}
|
||||
return blueprint;
|
||||
}
|
||||
|
||||
public static void addBlueprint(Blueprint blueprint) {
|
||||
if (blueprint == null)
|
||||
return;
|
||||
blueprints.put(blueprint.getUUID(), blueprint);
|
||||
}
|
||||
|
||||
private static File getBlueprintFolder() {
|
||||
File blueprintFolder = new File(configFolder, "buildcraft/blueprints/");
|
||||
if (!blueprintFolder.exists()) {
|
||||
blueprintFolder.mkdirs();
|
||||
}
|
||||
return blueprintFolder;
|
||||
}
|
||||
|
||||
private static String uuidToString(UUID uuid) {
|
||||
return String.format(Locale.ENGLISH, "%x%x", uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
public static void saveBlueprint(Blueprint blueprint) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
blueprint.writeToNBT(nbt);
|
||||
|
||||
File blueprintFile = new File(getBlueprintFolder(), String.format(Locale.ENGLISH, "%x%x-%s.nbt", uuidToString(blueprint.getUUID()), blueprint.getName()));
|
||||
|
||||
if (blueprintFile.exists())
|
||||
return;
|
||||
|
||||
try {
|
||||
CompressedStreamTools.write(nbt, blueprintFile);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger("Buildcraft").log(Level.SEVERE, String.format("Failed to save Blueprint file: %s %s", blueprintFile.getName(), ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveBlueprints() {
|
||||
for (Blueprint blueprint : blueprints.values()) {
|
||||
saveBlueprint(blueprint);
|
||||
}
|
||||
}
|
||||
|
||||
private static Blueprint loadBlueprint(final UUID uuid) {
|
||||
FilenameFilter filter = new FilenameFilter() {
|
||||
private String uuidString = uuidToString(uuid);
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.startsWith(uuidString);
|
||||
}
|
||||
};
|
||||
|
||||
NBTTagCompound nbt = null;
|
||||
File blueprintFolder = getBlueprintFolder();
|
||||
for (File blueprintFile : blueprintFolder.listFiles(filter)) {
|
||||
try {
|
||||
nbt = CompressedStreamTools.read(blueprintFile);
|
||||
break;
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger("Buildcraft").log(Level.SEVERE, String.format("Failed to load Blueprint file: %s %s", blueprintFile.getName(), ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
if (nbt == null) {
|
||||
return null;
|
||||
}
|
||||
return Blueprint.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
public static void loadBlueprints() {
|
||||
FilenameFilter filter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".nbt");
|
||||
}
|
||||
};
|
||||
File blueprintFolder = getBlueprintFolder();
|
||||
for (File blueprintFile : blueprintFolder.listFiles(filter)) {
|
||||
try {
|
||||
NBTTagCompound nbt = CompressedStreamTools.read(blueprintFile);
|
||||
addBlueprint(Blueprint.readFromNBT(nbt));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger("Buildcraft").log(Level.SEVERE, String.format("Failed to load Blueprint file: %s %s", blueprintFile.getName(), ex.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void sendBlueprintsToServer() {
|
||||
// TODO
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package buildcraft.builders.blueprints;
|
||||
|
||||
import buildcraft.api.builder.BlockHandler;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public final class ItemSchematic extends Schematic {
|
||||
|
||||
public static ItemSchematic create(NBTTagCompound nbt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemSchematic create(Item item) {
|
||||
return new ItemSchematic(item);
|
||||
}
|
||||
public final Item item;
|
||||
|
||||
private ItemSchematic(Item item) {
|
||||
super(item.itemID);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
private ItemSchematic(String itemName) {
|
||||
// String blockName = nbt.getString("blockName");
|
||||
this((Item) null); // TODO: Add item from name code
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockHandler getHandler() {
|
||||
return BlockHandler.get(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setString("schematicType", "item");
|
||||
nbt.setString("itemName", item.getUnlocalizedName());
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package buildcraft.builders.blueprints;
|
||||
|
||||
import buildcraft.api.builder.BlockHandler;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public final class MaskSchematic extends Schematic {
|
||||
|
||||
public static MaskSchematic create(NBTTagCompound nbt) {
|
||||
return new MaskSchematic();
|
||||
}
|
||||
|
||||
public static MaskSchematic create() {
|
||||
return new MaskSchematic();
|
||||
}
|
||||
|
||||
private MaskSchematic() {
|
||||
super(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockHandler getHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setString("schematicType", "mask");
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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.builders.blueprints;
|
||||
|
||||
import buildcraft.api.builder.BlockHandler;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public abstract class Schematic {
|
||||
|
||||
public final int id;
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
protected Schematic(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public abstract BlockHandler getHandler();
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("x", x);
|
||||
nbt.setInteger("y", y);
|
||||
nbt.setInteger("z", z);
|
||||
nbt.setCompoundTag("data", data);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
x = nbt.getInteger("x");
|
||||
y = nbt.getInteger("y");
|
||||
z = nbt.getInteger("z");
|
||||
data = nbt.getCompoundTag("data");
|
||||
}
|
||||
|
||||
public static Schematic createSchematicFromNBT(NBTTagCompound nbt) {
|
||||
String schematicType = nbt.getString("schematicType");
|
||||
Schematic schematic;
|
||||
if (schematicType.equals("block")) {
|
||||
schematic = BlockSchematic.create(nbt);
|
||||
} else if (schematicType.equals("item")) {
|
||||
schematic = ItemSchematic.create(nbt);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
schematic.x = nbt.getInteger("x");
|
||||
schematic.y = nbt.getInteger("y");
|
||||
schematic.z = nbt.getInteger("z");
|
||||
schematic.data = nbt.getCompoundTag("userData");
|
||||
return schematic;
|
||||
}
|
||||
}
|
|
@ -1,36 +1,63 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011-2012 http://www.mod-buildcraft.com
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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
|
||||
* 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 buildcraft.BuildCraftCore;
|
||||
import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.BlockUtil;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.core.blueprints.BptBuilderBase;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.blueprints.BptSlot;
|
||||
import buildcraft.core.blueprints.BptSlot.Mode;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.BlockUtil;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
|
||||
public class EntityRobot extends Entity implements IEntityAdditionalSpawnData {
|
||||
|
||||
private Box box;
|
||||
private int destX, destY, destZ;
|
||||
|
||||
EntityEnergyLaser laser;
|
||||
public LinkedList<SchematicBuilder> targets = new LinkedList<SchematicBuilder>();
|
||||
|
||||
public LinkedList<Action> targets = new LinkedList<Action>();
|
||||
public static int MAX_TARGETS = 20;
|
||||
public int wait = 0;
|
||||
|
||||
private class Action {
|
||||
|
||||
public Action(BptSlot slot, BptContext context) {
|
||||
this.slot = slot;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Action(BptBuilderBase builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
BptSlot slot;
|
||||
BptBuilderBase builder;
|
||||
BptContext context;
|
||||
}
|
||||
|
||||
public EntityRobot(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
@ -102,8 +129,6 @@ public class EntityRobot extends Entity implements IEntityAdditionalSpawnData {
|
|||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
if (CoreProxy.proxy.isRenderWorld(worldObj))
|
||||
return;
|
||||
|
||||
move();
|
||||
build();
|
||||
|
@ -174,31 +199,48 @@ public class EntityRobot extends Entity implements IEntityAdditionalSpawnData {
|
|||
|
||||
updateWait();
|
||||
|
||||
if (wait <= 0 && !targets.isEmpty()) {
|
||||
if (targets.size() > 0) {
|
||||
|
||||
SchematicBuilder target = targets.peek();
|
||||
if (target.blockExists()) {
|
||||
target.markComplete();
|
||||
targets.pop();
|
||||
} else if (BlockUtil.canChangeBlock(worldObj, target.getX(), target.getY(), target.getZ())) {
|
||||
Action a = targets.getFirst();
|
||||
if (a.slot != null) {
|
||||
|
||||
BptSlot target = a.slot;
|
||||
//System.out.printf("RobotChanging %d %d %d %s\n",target.x, target.y, target.z, target.mode);
|
||||
if (!worldObj.isAirBlock(target.getX(), target.getY(), target.getZ())) {
|
||||
BlockUtil.breakBlock(worldObj, target.getX(), target.getY(), target.getZ());
|
||||
if (wait <= 0 && BlockUtil.canChangeBlock(worldObj, target.x, target.y, target.z)) {
|
||||
|
||||
if (!CoreProxy.proxy.isRenderWorld(worldObj)) {
|
||||
|
||||
if (target.mode == Mode.ClearIfInvalid) {
|
||||
|
||||
if (!target.isValid(a.context)) {
|
||||
worldObj.setBlock(target.x, target.y, target.z, 0, 0,3);
|
||||
}
|
||||
|
||||
} else if (target.stackToUse != null) {
|
||||
|
||||
worldObj.setBlock(target.x, target.y, target.z, 0);
|
||||
throw new RuntimeException("NOT IMPLEMENTED");
|
||||
// target.stackToUse.getItem().onItemUse(target.stackToUse,
|
||||
// CoreProxy.getBuildCraftPlayer(worldObj), worldObj, target.x, target.y - 1,
|
||||
// target.z, 1);
|
||||
} else {
|
||||
targets.pop();
|
||||
|
||||
try {
|
||||
target.build(CoreProxy.proxy.getBuildCraftPlayer(worldObj, target.getX(), target.getY() + 2, target.getZ()));
|
||||
target.buildBlock(a.context);
|
||||
} catch (Throwable t) {
|
||||
target.markComplete();
|
||||
targets.pop();
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
BuildCraftCore.bcLog.throwing("EntityRobot", "update", t);
|
||||
}
|
||||
if (!target.isComplete()) {
|
||||
targets.addLast(target);
|
||||
}
|
||||
}
|
||||
|
||||
targets.pop();
|
||||
}
|
||||
|
||||
} else if (a.builder != null) {
|
||||
a.builder.postProcessing(worldObj);
|
||||
targets.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,10 +262,12 @@ public class EntityRobot extends Entity implements IEntityAdditionalSpawnData {
|
|||
|
||||
if (targets.size() > 0) {
|
||||
|
||||
SchematicBuilder target = targets.getFirst();
|
||||
Action a = targets.getFirst();
|
||||
BptSlotInfo target = a.slot;
|
||||
|
||||
if (target != null) {
|
||||
laser.setPositions(new Position(posX, posY, posZ), new Position(target.getX() + 0.5, target.getY() + 0.5, target.getZ() + 0.5));
|
||||
|
||||
laser.setPositions(new Position(posX, posY, posZ), new Position(target.x + 0.5, target.y + 0.5, target.z + 0.5));
|
||||
laser.show();
|
||||
}
|
||||
} else {
|
||||
|
@ -233,14 +277,16 @@ public class EntityRobot extends Entity implements IEntityAdditionalSpawnData {
|
|||
laser.pushPower(((float) targets.size()) / ((float) MAX_TARGETS) * 4F);
|
||||
}
|
||||
|
||||
public boolean scheduleContruction(SchematicBuilder schematic) {
|
||||
if (!readyToBuild()) {
|
||||
return false;
|
||||
public void scheduleContruction(BptSlot slot, BptContext context) {
|
||||
|
||||
if (slot != null) {
|
||||
targets.add(new Action(slot, context));
|
||||
|
||||
}
|
||||
if (schematic != null && !schematic.blockExists()) {
|
||||
return targets.add(schematic);
|
||||
}
|
||||
return false;
|
||||
|
||||
public void markEndOfBlueprint(BptBuilderBase builder) {
|
||||
targets.add(new Action(builder));
|
||||
}
|
||||
|
||||
public boolean readyToBuild() {
|
||||
|
@ -252,15 +298,19 @@ public class EntityRobot extends Entity implements IEntityAdditionalSpawnData {
|
|||
}
|
||||
|
||||
public void setBox(Box box) {
|
||||
|
||||
this.box = box;
|
||||
setDestination((int) box.centerX(), (int) box.centerY(), (int) box.centerZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDead() {
|
||||
|
||||
if (laser != null) {
|
||||
laser.setDead();
|
||||
}
|
||||
|
||||
super.setDead();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,11 +7,23 @@
|
|||
*/
|
||||
package buildcraft.factory;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Type;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftFactory;
|
||||
import buildcraft.builders.blueprints.Blueprint;
|
||||
import buildcraft.builders.blueprints.BlueprintBuilder;
|
||||
import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
|
||||
import buildcraft.api.core.IAreaProvider;
|
||||
import buildcraft.api.core.LaserKind;
|
||||
import buildcraft.api.gates.IAction;
|
||||
|
@ -25,31 +37,20 @@ import buildcraft.core.EntityRobot;
|
|||
import buildcraft.core.IBuilderInventory;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.blueprints.BptBlueprint;
|
||||
import buildcraft.core.blueprints.BptBuilderBase;
|
||||
import buildcraft.core.blueprints.BptBuilderBlueprint;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.network.TileNetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.BlockUtil;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.packet.Packet3Chat;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Type;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import static net.minecraftforge.common.ForgeDirection.*;
|
||||
|
||||
public class TileQuarry extends TileBuildCraft implements IMachine, IPowerReceptor, IPipeConnection, IBuilderInventory {
|
||||
|
||||
|
@ -66,8 +67,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
public @TileNetworkData
|
||||
boolean builderDone = false;
|
||||
public EntityRobot builder;
|
||||
private BlueprintBuilder blueprintBuilder;
|
||||
private ListIterator<SchematicBuilder> blueprintIterator;
|
||||
BptBuilderBase bluePrintBuilder;
|
||||
public EntityMechanicalArm arm;
|
||||
public PowerHandler powerHandler;
|
||||
boolean isDigging = false;
|
||||
|
@ -84,13 +84,13 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
}
|
||||
|
||||
public void createUtilsIfNeeded() {
|
||||
if (blueprintBuilder == null) {
|
||||
if (bluePrintBuilder == null) {
|
||||
|
||||
if (!box.isInitialized()) {
|
||||
setBoundaries(loadDefaultBoundaries);
|
||||
}
|
||||
|
||||
initializeBlueprintBuilder();
|
||||
initializeBluePrintBuilder();
|
||||
}
|
||||
|
||||
if (builderDone) {
|
||||
|
@ -125,8 +125,8 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
|
||||
private void createArm() {
|
||||
|
||||
worldObj.spawnEntityInWorld(new EntityMechanicalArm(worldObj, box.xMin + Utils.pipeMaxPos, yCoord + blueprintBuilder.blueprint.sizeY - 1
|
||||
+ Utils.pipeMinPos, box.zMin + Utils.pipeMaxPos, blueprintBuilder.blueprint.sizeX - 2 + Utils.pipeMinPos * 2, blueprintBuilder.blueprint.sizeZ
|
||||
worldObj.spawnEntityInWorld(new EntityMechanicalArm(worldObj, box.xMin + Utils.pipeMaxPos, yCoord + bluePrintBuilder.bluePrint.sizeY - 1
|
||||
+ Utils.pipeMinPos, box.zMin + Utils.pipeMaxPos, bluePrintBuilder.bluePrint.sizeX - 2 + Utils.pipeMinPos * 2, bluePrintBuilder.bluePrint.sizeZ
|
||||
- 2 + Utils.pipeMinPos * 2, this));
|
||||
}
|
||||
|
||||
|
@ -137,13 +137,15 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (!isAlive && CoreProxy.proxy.isSimulating(worldObj)) {
|
||||
super.updateEntity();
|
||||
return;
|
||||
}
|
||||
if (!CoreProxy.proxy.isSimulating(worldObj) && isAlive) {
|
||||
super.updateEntity();
|
||||
return;
|
||||
}
|
||||
super.updateEntity();
|
||||
if (inProcess) {
|
||||
float energyToUse = 2 + powerHandler.getEnergyStored() / 500;
|
||||
|
||||
|
@ -162,16 +164,23 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
|
||||
createUtilsIfNeeded();
|
||||
|
||||
if (blueprintBuilder != null) {
|
||||
if (bluePrintBuilder != null) {
|
||||
|
||||
builderDone = !blueprintIterator.hasNext();
|
||||
builderDone = bluePrintBuilder.done;
|
||||
if (!builderDone) {
|
||||
|
||||
buildFrame();
|
||||
return;
|
||||
} else if (builder != null && builder.done()) {
|
||||
killBuilder();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (builder != null && builder.done()) {
|
||||
|
||||
box.deleteLasers();
|
||||
builder.setDead();
|
||||
builder = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (builder == null) {
|
||||
|
@ -180,22 +189,14 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
|
||||
}
|
||||
|
||||
private void killBuilder() {
|
||||
box.deleteLasers();
|
||||
builder.setDead();
|
||||
builder = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider) {
|
||||
}
|
||||
|
||||
protected void buildFrame() {
|
||||
|
||||
if (!blueprintIterator.hasNext())
|
||||
return;
|
||||
|
||||
if (powerHandler.useEnergy(25, 25, false) != 25)
|
||||
powerHandler.configure(50, 100, 25, MAX_ENERGY);
|
||||
if (powerHandler.useEnergy(25, 25, true) != 25)
|
||||
return;
|
||||
|
||||
if (builder == null) {
|
||||
|
@ -204,12 +205,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
}
|
||||
|
||||
if (builder.readyToBuild()) {
|
||||
while (blueprintIterator.hasNext()) {
|
||||
if (builder.scheduleContruction(blueprintIterator.next())) {
|
||||
powerHandler.useEnergy(0, 25, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, this), bluePrintBuilder.getContext());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,17 +276,17 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
private void createColumnVisitList() {
|
||||
visitList.clear();
|
||||
|
||||
Integer[][] columnHeights = new Integer[blueprintBuilder.blueprint.sizeX - 2][blueprintBuilder.blueprint.sizeZ - 2];
|
||||
boolean[][] blockedColumns = new boolean[blueprintBuilder.blueprint.sizeX - 2][blueprintBuilder.blueprint.sizeZ - 2];
|
||||
Integer[][] columnHeights = new Integer[bluePrintBuilder.bluePrint.sizeX - 2][bluePrintBuilder.bluePrint.sizeZ - 2];
|
||||
boolean[][] blockedColumns = new boolean[bluePrintBuilder.bluePrint.sizeX - 2][bluePrintBuilder.bluePrint.sizeZ - 2];
|
||||
for (int searchY = yCoord + 3; searchY >= 0; --searchY) {
|
||||
int startX, endX, incX;
|
||||
|
||||
if (searchY % 2 == 0) {
|
||||
startX = 0;
|
||||
endX = blueprintBuilder.blueprint.sizeX - 2;
|
||||
endX = bluePrintBuilder.bluePrint.sizeX - 2;
|
||||
incX = 1;
|
||||
} else {
|
||||
startX = blueprintBuilder.blueprint.sizeX - 3;
|
||||
startX = bluePrintBuilder.bluePrint.sizeX - 3;
|
||||
endX = -1;
|
||||
incX = -1;
|
||||
}
|
||||
|
@ -300,10 +296,10 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
|
||||
if (searchX % 2 == searchY % 2) {
|
||||
startZ = 0;
|
||||
endZ = blueprintBuilder.blueprint.sizeZ - 2;
|
||||
endZ = bluePrintBuilder.bluePrint.sizeZ - 2;
|
||||
incZ = 1;
|
||||
} else {
|
||||
startZ = blueprintBuilder.blueprint.sizeZ - 3;
|
||||
startZ = bluePrintBuilder.bluePrint.sizeZ - 3;
|
||||
endZ = -1;
|
||||
incZ = -1;
|
||||
}
|
||||
|
@ -327,7 +323,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
visitList.add(new int[]{bx, by, bz});
|
||||
}
|
||||
// Stop at two planes - generally any obstructions will have been found and will force a recompute prior to this
|
||||
if (visitList.size() > blueprintBuilder.blueprint.sizeZ * blueprintBuilder.blueprint.sizeX * 2)
|
||||
if (visitList.size() > bluePrintBuilder.bluePrint.sizeZ * bluePrintBuilder.bluePrint.sizeX * 2)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -598,31 +594,38 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
forceChunkLoading(chunkTicket);
|
||||
}
|
||||
|
||||
private void initializeBlueprintBuilder() {
|
||||
Blueprint blueprint = new Blueprint(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
private void initializeBluePrintBuilder() {
|
||||
BptBlueprint bluePrint = new BptBlueprint(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
|
||||
for (int it = 0; it < 2; it++) {
|
||||
for (int i = 0; i < blueprint.sizeX; ++i) {
|
||||
blueprint.setSchematic(worldObj, i, it * (box.sizeY() - 1), 0, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setSchematic(worldObj, i, it * (box.sizeY() - 1), blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
for (int i = 0; i < bluePrint.sizeX; ++i) {
|
||||
for (int j = 0; j < bluePrint.sizeY; ++j) {
|
||||
for (int k = 0; k < bluePrint.sizeZ; ++k) {
|
||||
bluePrint.setBlockId(i, j, k, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < blueprint.sizeZ; ++k) {
|
||||
blueprint.setSchematic(worldObj, 0, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setSchematic(worldObj, blueprint.sizeX - 1, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
for (int it = 0; it < 2; it++) {
|
||||
for (int i = 0; i < bluePrint.sizeX; ++i) {
|
||||
bluePrint.setBlockId(i, it * (box.sizeY() - 1), 0, BuildCraftFactory.frameBlock.blockID);
|
||||
bluePrint.setBlockId(i, it * (box.sizeY() - 1), bluePrint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID);
|
||||
}
|
||||
|
||||
for (int k = 0; k < bluePrint.sizeZ; ++k) {
|
||||
bluePrint.setBlockId(0, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID);
|
||||
bluePrint.setBlockId(bluePrint.sizeX - 1, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (int h = 1; h < box.sizeY(); ++h) {
|
||||
blueprint.setSchematic(worldObj, 0, h, 0, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setSchematic(worldObj, 0, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setSchematic(worldObj, blueprint.sizeX - 1, h, 0, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setSchematic(worldObj, blueprint.sizeX - 1, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
bluePrint.setBlockId(0, h, 0, BuildCraftFactory.frameBlock.blockID);
|
||||
bluePrint.setBlockId(0, h, bluePrint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID);
|
||||
bluePrint.setBlockId(bluePrint.sizeX - 1, h, 0, BuildCraftFactory.frameBlock.blockID);
|
||||
bluePrint.setBlockId(bluePrint.sizeX - 1, h, bluePrint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID);
|
||||
}
|
||||
|
||||
blueprintBuilder = new BlueprintBuilder(blueprint, worldObj, box.xMin, yCoord, box.zMin, ForgeDirection.NORTH, null);
|
||||
blueprintIterator = blueprintBuilder.getBuilders().listIterator();
|
||||
bluePrintBuilder = new BptBuilderBlueprint(bluePrint, worldObj, box.xMin, yCoord, box.zMin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -657,10 +660,11 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
|
|||
|
||||
public void reinitalize() {
|
||||
builderDone = false;
|
||||
initializeBlueprintBuilder();
|
||||
initializeBluePrintBuilder();
|
||||
isDigging = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side) {
|
||||
return powerHandler.getPowerReceiver();
|
||||
|
|
Loading…
Reference in a new issue