made progress in builder robot, for #1908

This commit is contained in:
SpaceToad 2014-07-15 12:49:55 +02:00
parent bb72ff14ec
commit 0b710d998a
4 changed files with 42 additions and 13 deletions

View file

@ -13,6 +13,7 @@ import java.util.LinkedList;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.logging.Level; import java.util.logging.Level;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
@ -82,6 +83,7 @@ public abstract class BptBuilderBase implements IAreaProvider {
} }
if (slot != null) { if (slot != null) {
slot.built = true;
BuildingItem i = new BuildingItem(); BuildingItem i = new BuildingItem();
i.origin = new Position(x, y, z); i.origin = new Position(x, y, z);
i.destination = slot.getDestination(); i.destination = slot.getDestination();
@ -200,6 +202,10 @@ public abstract class BptBuilderBase implements IAreaProvider {
} }
} }
public void useRequirements(IInventory inv, BuildingSlot slot) {
}
public void saveBuildStateToNBT(NBTTagCompound nbt, IBuildingItemsProvider builder) { public void saveBuildStateToNBT(NBTTagCompound nbt, IBuildingItemsProvider builder) {
NBTTagList clearList = new NBTTagList(); NBTTagList clearList = new NBTTagList();

View file

@ -18,6 +18,7 @@ import java.util.Map.Entry;
import java.util.TreeSet; import java.util.TreeSet;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -320,10 +321,26 @@ public class BptBuilderBlueprint extends BptBuilderBase {
BuildingSlotBlock slot = iterator.next(); BuildingSlotBlock slot = iterator.next();
if (slot.buildStage > buildList.getFirst().buildStage) { if (slot.buildStage > buildList.getFirst().buildStage) {
iterator.reset (); iterator.reset();
return null; return null;
} }
if (slot.built) {
iterator.remove();
if (slot.mode == Mode.ClearIfInvalid) {
clearedLocations.add(new BlockIndex(slot.x,
slot.y, slot.z));
} else {
builtLocations.add(new BlockIndex(slot.x,
slot.y, slot.z));
}
postProcessing.add(slot);
continue;
}
if (slot.reserved) { if (slot.reserved) {
continue; continue;
} }
@ -370,6 +387,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
// When the item reaches the actual block, we'll // When the item reaches the actual block, we'll
// verify that the location is indeed clear, and // verify that the location is indeed clear, and
// avoid building otherwise. // avoid building otherwise.
builder.consumeEnergy(slot.getEnergyRequirement());
useRequirements(builder, slot); useRequirements(builder, slot);
iterator.remove(); iterator.remove();
@ -417,6 +435,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
it.remove(); it.remove();
} else { } else {
if (checkRequirements(builder, slot.schematic)) { if (checkRequirements(builder, slot.schematic)) {
builder.consumeEnergy(slot.getEnergyRequirement());
useRequirements(builder, slot); useRequirements(builder, slot);
it.remove(); it.remove();
@ -503,7 +522,12 @@ public class BptBuilderBlueprint extends BptBuilderBase {
return !(builder.energyAvailable() < slot.getEnergyRequirement(stacksUsed)); return !(builder.energyAvailable() < slot.getEnergyRequirement(stacksUsed));
} }
public void useRequirements(TileAbstractBuilder builder, BuildingSlot slot) { @Override
public void useRequirements(IInventory inv, BuildingSlot slot) {
if (slot instanceof BuildingSlotBlock && ((BuildingSlotBlock) slot).mode == Mode.ClearIfInvalid) {
return;
}
LinkedList<ItemStack> tmpReq = new LinkedList<ItemStack>(); LinkedList<ItemStack> tmpReq = new LinkedList<ItemStack>();
try { try {
@ -524,8 +548,6 @@ public class BptBuilderBlueprint extends BptBuilderBase {
slot.addStackConsumed(s); slot.addStackConsumed(s);
} }
builder.consumeEnergy(slot.getEnergyRequirement());
return; return;
} }
@ -539,12 +561,16 @@ public class BptBuilderBlueprint extends BptBuilderBase {
boolean itemBlock = reqStk.getItem() instanceof ItemBlock; boolean itemBlock = reqStk.getItem() instanceof ItemBlock;
Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).field_150939_a) : null; Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).field_150939_a) : null;
if (fluid != null && builder instanceof TileBuilder && ((TileBuilder) builder).drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) { if (fluid != null
&& inv instanceof TileBuilder
&& ((TileBuilder) inv)
.drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) {
continue; continue;
} }
for (IInvSlot slotInv : InventoryIterator.getIterable(builder, ForgeDirection.UNKNOWN)) { for (IInvSlot slotInv : InventoryIterator.getIterable(inv, ForgeDirection.UNKNOWN)) {
if (!builder.isBuildingMaterialSlot(slotInv.getIndex())) { if (inv instanceof TileAbstractBuilder &&
!((TileAbstractBuilder) inv).isBuildingMaterialSlot(slotInv.getIndex())) {
continue; continue;
} }
@ -581,8 +607,6 @@ public class BptBuilderBlueprint extends BptBuilderBase {
itr.set(usedStack); // set to the actual item used. itr.set(usedStack); // set to the actual item used.
} }
} }
builder.consumeEnergy(slot.getEnergyRequirement());
} }
public void recomputeNeededItems() { public void recomputeNeededItems() {

View file

@ -25,6 +25,8 @@ public abstract class BuildingSlot {
public boolean reserved = false; public boolean reserved = false;
public boolean built = false;
public void writeToWorld(IBuilderContext context) { public void writeToWorld(IBuilderContext context) {
} }

View file

@ -128,10 +128,7 @@ public class BoardRobotBuilder extends RedstoneBoardRobot {
return; return;
} }
// TODO: we want to update the markerToBuild.bluePrintBuilder.useRequirements(robot, currentBuildingSlot);
// builder state (remove slot from list, add to post processing,
// etc);
launchingDelay = currentBuildingSlot.getStacksToDisplay().size() * BuildingItem.ITEMS_SPACE; launchingDelay = currentBuildingSlot.getStacksToDisplay().size() * BuildingItem.ITEMS_SPACE;
markerToBuild.bluePrintBuilder.buildSlot markerToBuild.bluePrintBuilder.buildSlot
(robot.worldObj, markerToBuild, currentBuildingSlot, (robot.worldObj, markerToBuild, currentBuildingSlot,