progress in fixing back tile architect
This commit is contained in:
parent
e55950dee6
commit
b4deff27bd
11 changed files with 552 additions and 178 deletions
|
@ -18,6 +18,7 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
|
@ -123,4 +124,19 @@ public class BlockBuilder extends BlockContainer {
|
|||
blockTextureSide = par1IconRegister.registerIcon("buildcraft:builder_side");
|
||||
blockTextureFront = par1IconRegister.registerIcon("buildcraft:builder_front");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue(IBlockAccess world, int x, int y, int z) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,5 +24,6 @@ public class BuilderProxyClient extends BuilderProxy {
|
|||
super.registerBlockRenderers();
|
||||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileArchitect.class, new RenderBoxProvider());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileBuilder.class, new RenderBoxProvider());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ package buildcraft.builders;
|
|||
import buildcraft.builders.gui.ContainerBlueprintLibrary;
|
||||
import buildcraft.builders.gui.ContainerBuilder;
|
||||
import buildcraft.builders.gui.ContainerFiller;
|
||||
import buildcraft.builders.gui.ContainerTemplate;
|
||||
import buildcraft.builders.gui.ContainerArchitect;
|
||||
import buildcraft.builders.gui.GuiBlueprintLibrary;
|
||||
import buildcraft.builders.gui.GuiBuilder;
|
||||
import buildcraft.builders.gui.GuiFiller;
|
||||
import buildcraft.builders.gui.GuiTemplate;
|
||||
import buildcraft.builders.gui.GuiArchitect;
|
||||
import buildcraft.builders.urbanism.ContainerUrbanist;
|
||||
import buildcraft.builders.urbanism.GuiUrbanist;
|
||||
import buildcraft.builders.urbanism.TileUrbanist;
|
||||
|
@ -40,7 +40,7 @@ public class GuiHandler implements IGuiHandler {
|
|||
case GuiIds.ARCHITECT_TABLE:
|
||||
if (!(tile instanceof TileArchitect))
|
||||
return null;
|
||||
return new GuiTemplate(player.inventory, (TileArchitect) tile);
|
||||
return new GuiArchitect(player.inventory, (TileArchitect) tile);
|
||||
|
||||
case GuiIds.BLUEPRINT_LIBRARY:
|
||||
if (!(tile instanceof TileBlueprintLibrary))
|
||||
|
@ -82,7 +82,7 @@ public class GuiHandler implements IGuiHandler {
|
|||
case GuiIds.ARCHITECT_TABLE:
|
||||
if (!(tile instanceof TileArchitect))
|
||||
return null;
|
||||
return new ContainerTemplate(player.inventory, (TileArchitect) tile);
|
||||
return new ContainerArchitect(player.inventory, (TileArchitect) tile);
|
||||
|
||||
case GuiIds.BLUEPRINT_LIBRARY:
|
||||
if (!(tile instanceof TileBlueprintLibrary))
|
||||
|
|
|
@ -27,6 +27,9 @@ import buildcraft.core.blueprints.BptBlueprint;
|
|||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.blueprints.BptTemplate;
|
||||
import buildcraft.core.network.NetworkData;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.network.RPCSide;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public class TileArchitect extends TileBuildCraft implements IInventory, IBoxProvider {
|
||||
|
@ -81,8 +84,9 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
}
|
||||
|
||||
public void createBpt() {
|
||||
if (!box.isInitialized() || items[1] != null)
|
||||
if (!box.isInitialized() || items[1] != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BptBase result;
|
||||
BptContext context = null;
|
||||
|
@ -103,7 +107,8 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
result.anchorY = yCoord - box.yMin;
|
||||
result.anchorZ = zCoord - box.zMin;
|
||||
|
||||
ForgeDirection o = ForgeDirection.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)].getOpposite();
|
||||
ForgeDirection o = ForgeDirection.values()[worldObj.getBlockMetadata(
|
||||
xCoord, yCoord, zCoord)].getOpposite();
|
||||
|
||||
if (o == ForgeDirection.EAST) {
|
||||
// Do nothing
|
||||
|
@ -119,6 +124,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
}
|
||||
|
||||
ItemStack stack;
|
||||
|
||||
if (result.equals(BuildCraftBuilders.getBptRootIndex().getBluePrint(lastBptId))) {
|
||||
result = BuildCraftBuilders.getBptRootIndex().getBluePrint(lastBptId);
|
||||
stack = BuildCraftBuilders.getBptItemStack(items[0].getItem(), lastBptId, result.getName());
|
||||
|
@ -174,6 +180,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
return result;
|
||||
}
|
||||
|
||||
@RPC (RPCSide.SERVER)
|
||||
public void handleClientInput(char c) {
|
||||
if (c == 8) {
|
||||
if (name.length() > 0) {
|
||||
|
@ -184,7 +191,13 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
name += c;
|
||||
}
|
||||
}
|
||||
sendNetworkUpdate();
|
||||
|
||||
RPCHandler.rpcBroadcastPlayers(this, "setName", name);
|
||||
}
|
||||
|
||||
@RPC
|
||||
public void setName (String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -220,7 +233,6 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
items[i] = itemstack;
|
||||
|
||||
initializeComputing();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -312,10 +324,10 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
}
|
||||
|
||||
private void initializeComputing() {
|
||||
if (!box.isInitialized())
|
||||
if (!box.isInitialized()) {
|
||||
return;
|
||||
else if (!isComputing) {
|
||||
if (items[0] != null && items[0].getItem() instanceof ItemBptBase && items[1] == null) {
|
||||
} else if (!isComputing) {
|
||||
if (items[0] != null && items[0].getItem() instanceof ItemBlueprint && items[1] == null) {
|
||||
isComputing = true;
|
||||
computingTime = 0;
|
||||
} else {
|
||||
|
@ -323,7 +335,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
computingTime = 0;
|
||||
}
|
||||
} else {
|
||||
if (items[0] == null || !(items[0].getItem() instanceof ItemBptBase)) {
|
||||
if (items[0] == null || !(items[0].getItem() instanceof ItemBlueprint)) {
|
||||
isComputing = false;
|
||||
computingTime = 0;
|
||||
}
|
||||
|
|
|
@ -8,191 +8,429 @@
|
|||
*/
|
||||
package buildcraft.builders;
|
||||
|
||||
import java.util.ListIterator;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
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.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.gates.IAction;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import buildcraft.builders.blueprints.Blueprint;
|
||||
import buildcraft.builders.blueprints.BlueprintBuilder;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.Box.Kind;
|
||||
import buildcraft.core.EntityLaser;
|
||||
import buildcraft.core.IBoxProvider;
|
||||
import buildcraft.core.IBuilderInventory;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.inventory.InventoryMapper;
|
||||
import buildcraft.core.inventory.SimpleInventory;
|
||||
import buildcraft.core.blueprints.BptBase;
|
||||
import buildcraft.core.blueprints.BptBlueprint;
|
||||
import buildcraft.core.blueprints.BptBuilderBase;
|
||||
import buildcraft.core.blueprints.BptBuilderBlueprint;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.network.NetworkData;
|
||||
import buildcraft.core.robots.EntityRobotBuilder;
|
||||
import buildcraft.core.robots.EntityRobot;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IPowerReceptor, IMachine {
|
||||
public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
|
||||
IPowerReceptor, IMachine, IBoxProvider {
|
||||
|
||||
private final ItemStack items[] = new ItemStack[28];
|
||||
|
||||
private BptBuilderBase bluePrintBuilder;
|
||||
|
||||
@NetworkData
|
||||
public Box box = new Box();
|
||||
|
||||
private static final int SLOT_BLUEPRINT = 0;
|
||||
public @NetworkData
|
||||
Box box = new Box();
|
||||
private PowerHandler powerHandler;
|
||||
private EntityRobotBuilder builderRobot;
|
||||
private BlueprintBuilder blueprintBuilder;
|
||||
private ListIterator<BlueprintBuilder.SchematicBuilder> blueprintIterator;
|
||||
private boolean builderDone = false;
|
||||
private SimpleInventory inv = new SimpleInventory(28, "Builder", 64);
|
||||
private IInventory invStock = new InventoryMapper(inv, 1, 27);
|
||||
private Blueprint blueprint;
|
||||
|
||||
private LinkedList<BlockIndex> path;
|
||||
|
||||
private LinkedList<EntityLaser> pathLasers;
|
||||
|
||||
private EntityRobot builderRobot;
|
||||
|
||||
private class PathIterator {
|
||||
|
||||
public Iterator<BlockIndex> currentIterator;
|
||||
public double cx, cy, cz;
|
||||
public float ix, iy, iz;
|
||||
public BlockIndex to;
|
||||
public double lastDistance;
|
||||
AxisAlignedBB oldBoundingBox = null;
|
||||
ForgeDirection o = null;
|
||||
|
||||
public PathIterator(BlockIndex from, Iterator<BlockIndex> it) {
|
||||
this.to = it.next();
|
||||
|
||||
currentIterator = it;
|
||||
|
||||
double dx = to.x - from.z;
|
||||
double dy = to.y - from.y;
|
||||
double dz = to.z - from.z;
|
||||
|
||||
double size = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
|
||||
cx = dx / size / 10;
|
||||
cy = dy / size / 10;
|
||||
cz = dz / size / 10;
|
||||
|
||||
ix = from.x;
|
||||
iy = from.y;
|
||||
iz = from.z;
|
||||
|
||||
lastDistance = (ix - to.x) * (ix - to.x) + (iy - to.y)
|
||||
* (iy - to.y) + (iz - to.z) * (iz - to.z);
|
||||
|
||||
if (Math.abs(dx) > Math.abs(dz)) {
|
||||
if (dx > 0) {
|
||||
o = ForgeDirection.EAST;
|
||||
} else {
|
||||
o = ForgeDirection.WEST;
|
||||
}
|
||||
} else {
|
||||
if (dz > 0) {
|
||||
o = ForgeDirection.SOUTH;
|
||||
} else {
|
||||
o = ForgeDirection.NORTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return false when reached the end of the iteration
|
||||
*/
|
||||
public BptBuilderBase next() {
|
||||
while (true) {
|
||||
BptBuilderBase bpt;
|
||||
|
||||
int newX = Math.round(ix);
|
||||
int newY = Math.round(iy);
|
||||
int newZ = Math.round(iz);
|
||||
|
||||
bpt = instanciateBluePrint(newX, newY, newZ, o);
|
||||
|
||||
if (bpt == null)
|
||||
return null;
|
||||
|
||||
AxisAlignedBB boundingBox = bpt.getBoundingBox();
|
||||
|
||||
if (oldBoundingBox == null || !collision(oldBoundingBox, boundingBox)) {
|
||||
|
||||
oldBoundingBox = boundingBox;
|
||||
|
||||
if (bpt != null)
|
||||
return bpt;
|
||||
}
|
||||
|
||||
ix += cx;
|
||||
iy += cy;
|
||||
iz += cz;
|
||||
|
||||
double distance = (ix - to.x) * (ix - to.x) + (iy - to.y)
|
||||
* (iy - to.y) + (iz - to.z) * (iz - to.z);
|
||||
|
||||
if (distance > lastDistance)
|
||||
return null;
|
||||
else {
|
||||
lastDistance = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PathIterator iterate() {
|
||||
if (currentIterator.hasNext()) {
|
||||
PathIterator next = new PathIterator(to, currentIterator);
|
||||
next.oldBoundingBox = oldBoundingBox;
|
||||
|
||||
return next;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean collision(AxisAlignedBB left, AxisAlignedBB right) {
|
||||
if (left.maxX < right.minX || left.minX > right.maxX)
|
||||
return false;
|
||||
if (left.maxY < right.minY || left.minY > right.maxY)
|
||||
return false;
|
||||
if (left.maxZ < right.minZ || left.minZ > right.maxZ)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public PathIterator currentPathIterator;
|
||||
|
||||
private boolean done = true;
|
||||
|
||||
public TileBuilder() {
|
||||
super();
|
||||
|
||||
powerHandler = new PowerHandler(this, Type.MACHINE);
|
||||
powerHandler.configure(25, 25, 25, 100);
|
||||
powerHandler.configure(25, 25, 25, 25);
|
||||
|
||||
box.kind = Kind.STRIPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
setupBuilder();
|
||||
for (int x = xCoord - 1; x <= xCoord + 1; ++x) {
|
||||
for (int y = yCoord - 1; y <= yCoord + 1; ++y) {
|
||||
for (int z = zCoord - 1; z <= zCoord + 1; ++z) {
|
||||
TileEntity tile = worldObj.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof TilePathMarker) {
|
||||
path = ((TilePathMarker) tile).getPath();
|
||||
|
||||
for (BlockIndex b : path) {
|
||||
worldObj.setBlockToAir(b.x, b.y, b.z);
|
||||
|
||||
BuildCraftBuilders.pathMarkerBlock.dropBlockAsItem(
|
||||
worldObj, b.x, b.y, b.z,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path != null && pathLasers == null) {
|
||||
path.getFirst().x = xCoord;
|
||||
path.getFirst().y = yCoord;
|
||||
path.getFirst().z = zCoord;
|
||||
|
||||
createLasersForPath();
|
||||
}
|
||||
|
||||
iterateBpt();
|
||||
}
|
||||
|
||||
public void createLasersForPath() {
|
||||
/*pathLasers = new LinkedList<EntityLaser>();
|
||||
BlockIndex previous = null;
|
||||
|
||||
for (BlockIndex b : path) {
|
||||
if (previous != null) {
|
||||
EntityPowerLaser laser = new EntityPowerLaser(worldObj, new Position(previous.i + 0.5, previous.j + 0.5, previous.k + 0.5), new Position(
|
||||
b.x + 0.5, b.y + 0.5, b.z + 0.5));
|
||||
|
||||
laser.setTexture(DefaultProps.TEXTURE_PATH_ENTITIES + "/laser_1.png");
|
||||
laser.show();
|
||||
worldObj.spawnEntityInWorld(laser);
|
||||
pathLasers.add(laser);
|
||||
}
|
||||
|
||||
previous = b;
|
||||
}*/
|
||||
}
|
||||
|
||||
public BptBuilderBase instanciateBluePrint(int x, int y, int z, ForgeDirection o) {
|
||||
BptBase bpt = BuildCraftBuilders.getBptRootIndex().getBluePrint(items[0].getItemDamage());
|
||||
|
||||
if (bpt == null)
|
||||
return null;
|
||||
|
||||
bpt = bpt.clone();
|
||||
|
||||
BptContext context = new BptContext(worldObj, null, bpt.getBoxForPos(x, y, z));
|
||||
|
||||
if (o == ForgeDirection.EAST) {
|
||||
// Do nothing
|
||||
} else if (o == ForgeDirection.SOUTH) {
|
||||
bpt.rotateLeft(context);
|
||||
} else if (o == ForgeDirection.WEST) {
|
||||
bpt.rotateLeft(context);
|
||||
bpt.rotateLeft(context);
|
||||
} else if (o == ForgeDirection.NORTH) {
|
||||
bpt.rotateLeft(context);
|
||||
bpt.rotateLeft(context);
|
||||
bpt.rotateLeft(context);
|
||||
}
|
||||
|
||||
if (items[0].getItem() instanceof ItemBlueprintTemplate)
|
||||
return new BptBuilderTemplate(bpt, worldObj, x, y, z);
|
||||
else if (items[0].getItem() instanceof ItemBptBluePrint)
|
||||
return new BptBuilderBlueprint((BptBlueprint) bpt, worldObj, x, y, z);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider) {
|
||||
if (worldObj.isRemote)
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
|
||||
if (builderDone)
|
||||
return;
|
||||
|
||||
build();
|
||||
}
|
||||
|
||||
public Blueprint getBlueprint() {
|
||||
ItemStack blueprintStack = getStackInSlot(SLOT_BLUEPRINT);
|
||||
return ItemBlueprint.getBlueprint(blueprintStack);
|
||||
}
|
||||
|
||||
public BlueprintBuilder getBlueprintBuilder() {
|
||||
return blueprintBuilder;
|
||||
}
|
||||
|
||||
private void setupBuilder() {
|
||||
Blueprint newBlueprint = getBlueprint();
|
||||
if (blueprint != newBlueprint) {
|
||||
blueprint = newBlueprint;
|
||||
reset();
|
||||
builderDone = false;
|
||||
}
|
||||
if (!builderDone && blueprintBuilder == null && blueprint != null) {
|
||||
ForgeDirection blueprintOrientation = ForgeDirection.NORTH;
|
||||
switch (ForgeDirection.getOrientation(getBlockMetadata())) {
|
||||
case WEST:
|
||||
blueprintOrientation = blueprintOrientation.getRotation(ForgeDirection.UP);
|
||||
case SOUTH:
|
||||
blueprintOrientation = blueprintOrientation.getRotation(ForgeDirection.UP);
|
||||
case EAST:
|
||||
blueprintOrientation = blueprintOrientation.getRotation(ForgeDirection.UP);
|
||||
|
||||
if (done) {
|
||||
return;
|
||||
//}// else if (builderRobot != null && !builderRobot.readyToBuild()) {
|
||||
// return;
|
||||
} else if (powerHandler.useEnergy(25, 25, true) < 25) {
|
||||
return;
|
||||
}
|
||||
|
||||
iterateBpt();
|
||||
|
||||
/* Temp fix to make Builders impotent as the World Destroyers they are
|
||||
if (bluePrintBuilder != null && !bluePrintBuilder.done) {
|
||||
if (!box.isInitialized()) {
|
||||
box.initialize(bluePrintBuilder);
|
||||
}
|
||||
switch (blueprint.anchorOrientation) {
|
||||
case WEST:
|
||||
blueprintOrientation = blueprintOrientation.getRotation(ForgeDirection.DOWN);
|
||||
case SOUTH:
|
||||
blueprintOrientation = blueprintOrientation.getRotation(ForgeDirection.DOWN);
|
||||
case EAST:
|
||||
blueprintOrientation = blueprintOrientation.getRotation(ForgeDirection.DOWN);
|
||||
|
||||
if (builderRobot == null) {
|
||||
builderRobot = new EntityRobot(worldObj, box);
|
||||
worldObj.spawnEntityInWorld(builderRobot);
|
||||
}
|
||||
blueprintBuilder = new BlueprintBuilder(blueprint, worldObj, xCoord, yCoord, zCoord, blueprintOrientation);
|
||||
blueprintIterator = blueprintBuilder.getBuilders().listIterator();
|
||||
box.initialize(blueprintBuilder);
|
||||
box.reorder();
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
if (!hasWorkScheduled()) {
|
||||
reset();
|
||||
builderDone = true;
|
||||
box.createLasers(worldObj, LaserKind.Stripes);
|
||||
|
||||
builderRobot.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, new SurroundingInventory(worldObj, xCoord, yCoord, zCoord)),
|
||||
bluePrintBuilder.getContext());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
box.reset();
|
||||
blueprintBuilder = null;
|
||||
blueprintIterator = null;
|
||||
killRobot();
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
public void iterateBpt() {
|
||||
if (items[0] == null || !(items[0].getItem() instanceof ItemBptBase)) {
|
||||
|
||||
private void killRobot() {
|
||||
if (builderRobot != null) {
|
||||
builderRobot.setDead();
|
||||
builderRobot = null;
|
||||
}
|
||||
}
|
||||
if (bluePrintBuilder != null) {
|
||||
bluePrintBuilder = null;
|
||||
}
|
||||
|
||||
if (builderRobot != null) {
|
||||
builderRobot.setDead();
|
||||
builderRobot = null;
|
||||
}
|
||||
|
||||
if (box.isInitialized()) {
|
||||
box.reset();
|
||||
}
|
||||
|
||||
if (currentPathIterator != null) {
|
||||
currentPathIterator = null;
|
||||
}
|
||||
|
||||
private void build() {
|
||||
if (blueprintBuilder == null) {
|
||||
return;
|
||||
} else if (blueprintIterator == null) {
|
||||
return;
|
||||
} else if (!blueprintIterator.hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
float mj = 25;
|
||||
if (bluePrintBuilder == null || bluePrintBuilder.done) {
|
||||
if (path != null && path.size() > 1) {
|
||||
if (currentPathIterator == null) {
|
||||
Iterator<BlockIndex> it = path.iterator();
|
||||
BlockIndex start = it.next();
|
||||
currentPathIterator = new PathIterator(start, it);
|
||||
}
|
||||
|
||||
if (powerHandler.useEnergy(mj, mj, true) != mj) {
|
||||
return;
|
||||
if (bluePrintBuilder != null && builderRobot != null) {
|
||||
//builderRobot.markEndOfBlueprint(bluePrintBuilder);
|
||||
}
|
||||
|
||||
bluePrintBuilder = currentPathIterator.next();
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
box.reset();
|
||||
/*
|
||||
box.initialize(bluePrintBuilder);
|
||||
*/
|
||||
}
|
||||
|
||||
if (builderRobot != null) {
|
||||
//builderRobot.setBox(box);
|
||||
}
|
||||
|
||||
if (bluePrintBuilder == null) {
|
||||
currentPathIterator = currentPathIterator.iterate();
|
||||
}
|
||||
|
||||
if (currentPathIterator == null) {
|
||||
done = true;
|
||||
}
|
||||
} else {
|
||||
if (bluePrintBuilder != null && bluePrintBuilder.done) {
|
||||
if (builderRobot != null) {
|
||||
//builderRobot.markEndOfBlueprint(bluePrintBuilder);
|
||||
}
|
||||
|
||||
done = true;
|
||||
bluePrintBuilder = null;
|
||||
} else {
|
||||
bluePrintBuilder = instanciateBluePrint(xCoord, yCoord, zCoord,
|
||||
ForgeDirection.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)].getOpposite());
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
box.initialize(bluePrintBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if (builderRobot == null) {
|
||||
// builderRobot = new EntityRobotBuilder(worldObj, box);
|
||||
// worldObj.spawnEntityInWorld(builderRobot);
|
||||
//}
|
||||
|
||||
//if (builderRobot.readyToBuild()) {
|
||||
// while (blueprintIterator.hasNext()) {
|
||||
// if (builderRobot.scheduleContruction(blueprintIterator.next())) {
|
||||
// powerHandler.useEnergy(0, 25, true);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public boolean hasWorkScheduled() {
|
||||
return (blueprintIterator != null && blueprintIterator.hasNext()) || (builderRobot != null /*&& !builderRobot.done()*/);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inv.getSizeInventory();
|
||||
return items.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inv.getStackInSlot(slot);
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return items[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
return inv.decrStackSize(slot, amount);
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
ItemStack result;
|
||||
if (items[i] == null) {
|
||||
result = null;
|
||||
} else if (items[i].stackSize > j) {
|
||||
result = items[i].splitStack(j);
|
||||
} else {
|
||||
ItemStack tmp = items[i];
|
||||
items[i] = null;
|
||||
result = tmp;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
iterateBpt();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
inv.setInventorySlotContents(slot, stack);
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
items[i] = itemstack;
|
||||
|
||||
if (i == 0) {
|
||||
iterateBpt();
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return inv.getStackInSlotOnClosing(slot);
|
||||
if (items[slot] == null)
|
||||
return null;
|
||||
ItemStack toReturn = items[slot];
|
||||
items[slot] = null;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -205,45 +443,59 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
|
|||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
if (slot == SLOT_BLUEPRINT) {
|
||||
return ItemBlueprint.getBlueprint(stack) != null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
inv.readFromNBT(nbt);
|
||||
Utils.readStacksFromNBT(nbttagcompound, "Items", items);
|
||||
|
||||
if (nbt.hasKey("box")) {
|
||||
box.initialize(nbt.getCompoundTag("box"));
|
||||
if (nbttagcompound.hasKey("box")) {
|
||||
box.initialize(nbttagcompound.getCompoundTag("box"));
|
||||
}
|
||||
|
||||
builderDone = nbt.getBoolean("builderDone");
|
||||
if (nbttagcompound.hasKey("path")) {
|
||||
path = new LinkedList<BlockIndex>();
|
||||
NBTTagList list = nbttagcompound.getTagList("path",
|
||||
Utils.NBTTag_Types.NBTTagCompound.ordinal());
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
path.add(new BlockIndex(list.getCompoundTagAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
done = nbttagcompound.getBoolean("done");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
inv.writeToNBT(nbt);
|
||||
Utils.writeStacksToNBT(nbttagcompound, "Items", items);
|
||||
|
||||
if (box.isInitialized()) {
|
||||
NBTTagCompound boxStore = new NBTTagCompound();
|
||||
box.writeToNBT(boxStore);
|
||||
nbt.setTag("box", boxStore);
|
||||
nbttagcompound.setTag("box", boxStore);
|
||||
}
|
||||
|
||||
nbt.setBoolean("builderDone", builderDone);
|
||||
if (path != null) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for (BlockIndex i : path) {
|
||||
NBTTagCompound c = new NBTTagCompound();
|
||||
i.writeTo(c);
|
||||
list.appendTag(c);
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("path", list);
|
||||
}
|
||||
|
||||
nbttagcompound.setBoolean("done", done);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -258,11 +510,8 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
|
|||
builderRobot.setDead();
|
||||
builderRobot = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side) {
|
||||
return powerHandler.getPowerReceiver();
|
||||
cleanPathLasers();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -273,9 +522,34 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
|
|||
public void closeInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if ((bluePrintBuilder == null || bluePrintBuilder.done)
|
||||
&& box.isInitialized()
|
||||
//&& (builderRobot == null || builderRobot.done())
|
||||
) {
|
||||
|
||||
box.isVisible = false;
|
||||
box.reset();
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!box.isInitialized() && bluePrintBuilder == null && builderRobot != null) {
|
||||
builderRobot.setDead();
|
||||
builderRobot = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return !builderDone;
|
||||
return !done;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -288,6 +562,28 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
|
|||
return true;
|
||||
}
|
||||
|
||||
public void cleanPathLasers() {
|
||||
if (pathLasers != null) {
|
||||
for (EntityLaser laser : pathLasers) {
|
||||
laser.setDead();
|
||||
}
|
||||
|
||||
pathLasers = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBuildingBlueprint() {
|
||||
return getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof ItemBptBluePrint;
|
||||
}
|
||||
|
||||
public Collection<ItemStack> getNeededItems() {
|
||||
if (bluePrintBuilder instanceof BptBuilderBlueprint) {
|
||||
return ((BptBuilderBlueprint) bluePrintBuilder).neededItems;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuildingMaterial(int i) {
|
||||
return i != 0;
|
||||
|
@ -300,6 +596,28 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
|
|||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int var1, ItemStack var2) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return new Box (this).extendToEncompass(box).getBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side) {
|
||||
return powerHandler.getPowerReceiver();
|
||||
}
|
||||
}
|
|
@ -15,13 +15,13 @@ import net.minecraft.inventory.ICrafting;
|
|||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
public class ContainerTemplate extends BuildCraftContainer {
|
||||
public class ContainerArchitect extends BuildCraftContainer {
|
||||
|
||||
protected IInventory playerIInventory;
|
||||
protected TileArchitect template;
|
||||
protected int computingTime = 0;
|
||||
|
||||
public ContainerTemplate(IInventory playerInventory, TileArchitect template) {
|
||||
public ContainerArchitect(IInventory playerInventory, TileArchitect template) {
|
||||
super(template.getSizeInventory());
|
||||
this.playerIInventory = playerInventory;
|
||||
this.template = template;
|
|
@ -27,15 +27,15 @@ import net.minecraft.util.ResourceLocation;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiTemplate extends GuiBuildCraft {
|
||||
public class GuiArchitect extends GuiBuildCraft {
|
||||
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/template_gui.png");
|
||||
IInventory playerInventory;
|
||||
TileArchitect template;
|
||||
boolean editMode = false;
|
||||
|
||||
public GuiTemplate(IInventory playerInventory, TileArchitect template) {
|
||||
super(new ContainerTemplate(playerInventory, template), template, TEXTURE);
|
||||
public GuiArchitect(IInventory playerInventory, TileArchitect template) {
|
||||
super(new ContainerArchitect(playerInventory, template), template, TEXTURE);
|
||||
this.playerInventory = playerInventory;
|
||||
this.template = template;
|
||||
xSize = 175;
|
|
@ -8,21 +8,17 @@
|
|||
*/
|
||||
package buildcraft.builders.gui;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import buildcraft.builders.TileBuilder;
|
||||
import buildcraft.builders.blueprints.Blueprint;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.gui.AdvancedSlot;
|
||||
import buildcraft.core.gui.GuiAdvancedInterface;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiBuilder extends GuiAdvancedInterface {
|
||||
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/builder.png");
|
||||
|
@ -55,7 +51,7 @@ public class GuiBuilder extends GuiAdvancedInterface {
|
|||
fontRendererObj.drawString(StringUtils.localize("gui.building.resources"), 8, 60, 0x404040);
|
||||
fontRendererObj.drawString(StringUtils.localize("gui.inventory"), 8, ySize - 97, 0x404040);
|
||||
fontRendererObj.drawString(StringUtils.localize("gui.needed"), 185, 7, 0x404040);
|
||||
|
||||
|
||||
drawForegroundSelection(par1, par2);
|
||||
}
|
||||
|
||||
|
@ -80,7 +76,7 @@ public class GuiBuilder extends GuiAdvancedInterface {
|
|||
((ItemSlot) slots[s]).stack = null;
|
||||
}
|
||||
|
||||
Blueprint blueprint = builder.getBlueprint();
|
||||
/*Blueprint blueprint = builder.getBlueprint();
|
||||
if(blueprint != null){
|
||||
Collection<ItemStack> needs = blueprint.getCost();
|
||||
|
||||
|
@ -96,7 +92,7 @@ public class GuiBuilder extends GuiAdvancedInterface {
|
|||
s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
drawBackgroundSlots();
|
||||
}
|
||||
|
|
|
@ -14,9 +14,12 @@ import java.io.IOException;
|
|||
import java.util.TreeSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
import buildcraft.core.IBptContributor;
|
||||
import buildcraft.core.utils.BCLog;
|
||||
|
||||
public class BptBlueprint extends BptBase {
|
||||
|
||||
|
@ -39,15 +42,15 @@ public class BptBlueprint extends BptBase {
|
|||
}
|
||||
|
||||
public void readFromWorld(IBptContext context, TileEntity anchorTile, int x, int y, int z) {
|
||||
/*BptSlot slot = new BptSlot();
|
||||
BptSlot slot = new BptSlot();
|
||||
|
||||
slot.x = (int) (x - context.surroundingBox().pMin().x);
|
||||
slot.y = (int) (y - context.surroundingBox().pMin().y);
|
||||
slot.z = (int) (z - context.surroundingBox().pMin().z);
|
||||
slot.blockId = anchorTile.getWorldObj().getBlockId(x, y, z);
|
||||
slot.block = anchorTile.getWorldObj().getBlock(x, y, z);
|
||||
slot.meta = anchorTile.getWorldObj().getBlockMetadata(x, y, z);
|
||||
|
||||
if (Block.blocksList[slot.blockId] instanceof BlockContainer) {
|
||||
if (slot.block instanceof BlockContainer) {
|
||||
TileEntity tile = anchorTile.getWorldObj().getTileEntity(x, y, z);
|
||||
|
||||
if (tile != null && tile instanceof IBptContributor) {
|
||||
|
@ -64,8 +67,7 @@ public class BptBlueprint extends BptBase {
|
|||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
BCLog.logger.throwing("BptBlueprint", "readFromWorld", t);
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -256,7 +256,7 @@ public class RPCHandler {
|
|||
// special last argument RPCMessageInfo
|
||||
|
||||
throw new RuntimeException(getClass().getName() + "." + method
|
||||
+ " expects " + m.parameters.length + "parameters, not " + actuals.length);
|
||||
+ " expects " + m.parameters.length + " parameters, not " + actuals.length);
|
||||
}
|
||||
|
||||
data.writeShort(methodIndex);
|
||||
|
|
|
@ -25,6 +25,7 @@ import net.minecraft.inventory.IInventory;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
@ -523,4 +524,32 @@ public class Utils {
|
|||
|
||||
return new FMLProxyPacket(buf, DefaultProps.NET_CHANNEL_NAME + "-CORE");
|
||||
}
|
||||
|
||||
public static void readStacksFromNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
|
||||
NBTTagList nbttaglist = nbt.getTagList(name, NBTTag_Types.NBTTagCompound.ordinal());
|
||||
|
||||
for (int i = 0; i < stacks.length; ++i)
|
||||
if (i < nbttaglist.tagCount()) {
|
||||
NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(i);
|
||||
|
||||
stacks[i] = ItemStack.loadItemStackFromNBT(nbttagcompound2);
|
||||
} else {
|
||||
stacks[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeStacksToNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < stacks.length; ++i) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
nbttaglist.appendTag(cpt);
|
||||
if (stacks[i] != null) {
|
||||
stacks[i].writeToNBT(cpt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
nbt.setTag(name, nbttaglist);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue