use of buildcraft.core.builders.BuildingSlotEntity in project BuildCraft by BuildCraft.
the class BptBuilderBlueprint method internalGetNextEntity.
// TODO: Remove recomputeNeededItems() and replace with something more efficient
private BuildingSlot internalGetNextEntity(World world, TileAbstractBuilder builder) {
Iterator<BuildingSlotEntity> it = entityList.iterator();
while (it.hasNext()) {
BuildingSlotEntity slot = it.next();
if (slot.isAlreadyBuilt(context)) {
it.remove();
recomputeNeededItems();
} else {
if (checkRequirements(builder, slot.schematic)) {
builder.consumeEnergy(slot.getEnergyRequirement());
useRequirements(builder, slot);
it.remove();
recomputeNeededItems();
postProcessing.add(slot);
builtEntities.add(slot.sequenceNumber);
return slot;
}
}
}
return null;
}
use of buildcraft.core.builders.BuildingSlotEntity in project BuildCraft by BuildCraft.
the class BptBuilderBlueprint method recomputeNeededItems.
private void recomputeNeededItems() {
neededItems.clear();
HashMap<StackKey, Integer> computeStacks = new HashMap<>();
for (List<BuildingSlotBlock> lb : buildList.values()) {
for (BuildingSlotBlock slot : lb) {
if (slot == null) {
continue;
}
List<ItemStack> stacks = new ArrayList<>();
try {
stacks = slot.getRequirements(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
for (ItemStack stack : stacks) {
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
StackKey key = new StackKey(stack);
if (!computeStacks.containsKey(key)) {
computeStacks.put(key, stack.stackSize);
} else {
Integer num = computeStacks.get(key);
num += stack.stackSize;
computeStacks.put(key, num);
}
}
}
}
for (BuildingSlotEntity slot : entityList) {
LinkedList<ItemStack> stacks = new LinkedList<>();
try {
stacks = slot.getRequirements(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
for (ItemStack stack : stacks) {
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
StackKey key = new StackKey(stack);
if (!computeStacks.containsKey(key)) {
computeStacks.put(key, stack.stackSize);
} else {
Integer num = computeStacks.get(key);
num += stack.stackSize;
computeStacks.put(key, num);
}
}
}
for (Entry<StackKey, Integer> e : computeStacks.entrySet()) {
neededItems.add(new RequirementItemStack(e.getKey().stack.copy(), e.getValue()));
}
sortNeededItems();
}
use of buildcraft.core.builders.BuildingSlotEntity in project BuildCraft by BuildCraft.
the class BptBuilderBlueprint method internalInit.
@Override
protected void internalInit() {
BlockPos worldOffset = pos.subtract(blueprint.anchor);
BlockPos bptMin = BlockPos.ORIGIN;
if (worldOffset.getY() < 0)
bptMin = VecUtil.replaceValue(bptMin, Axis.Y, -worldOffset.getY());
BlockPos bptMax = blueprint.size.subtract(Utils.POS_ONE);
if (worldOffset.add(bptMax).getY() > context.world().getHeight()) {
bptMax = VecUtil.replaceValue(bptMax, Axis.Y, context.world().getHeight() - worldOffset.getY());
}
/* Check to make sure the max is bigger than the min- if its not it means that the size was 0 for one of the
* axis */
if (Utils.min(bptMin, bptMax).equals(bptMin) && Utils.max(bptMin, bptMax).equals(bptMax)) {
try {
for (BlockPos bptOffset : Utils.getAllInBox(bptMin, bptMax, getOrder())) {
BlockPos pointWorldOffset = worldOffset.add(bptOffset);
if (!isLocationUsed(pointWorldOffset)) {
SchematicBlock slot = (SchematicBlock) blueprint.get(bptOffset);
if (slot == null && !blueprint.excavate) {
continue;
}
if (slot == null) {
slot = new SchematicBlock();
slot.state = Blocks.AIR.getDefaultState();
}
if (!SchematicRegistry.INSTANCE.isAllowedForBuilding(slot.state)) {
continue;
}
BuildingSlotBlock b = new BuildingSlotBlock();
b.schematic = slot;
b.pos = pointWorldOffset;
b.mode = Mode.ClearIfInvalid;
b.buildStage = 0;
addToBuildList(b);
}
}
} catch (ArrayIndexOutOfBoundsException aioobe) {
BCLog.logger.warn("Attempted to use the positions " + bptMin + ", " + bptMax + " to access a blueprint with a size of " + blueprint.size);
throw BCLog.logger.throwing(aioobe);
}
LinkedList<BuildingSlotBlock> tmpStandalone = new LinkedList<>();
LinkedList<BuildingSlotBlock> tmpExpanding = new LinkedList<>();
for (BlockPos bptOffset : Utils.getAllInBox(bptMin, bptMax, getOrder())) {
BlockPos pointWorldOffset = worldOffset.add(bptOffset);
SchematicBlock slot = (SchematicBlock) blueprint.get(bptOffset);
if (slot == null) {
continue;
}
if (!SchematicRegistry.INSTANCE.isAllowedForBuilding(slot.state)) {
continue;
}
BuildingSlotBlock b = new BuildingSlotBlock();
b.schematic = slot;
b.pos = pointWorldOffset;
b.mode = Mode.Build;
if (!isLocationUsed(pointWorldOffset)) {
switch(slot.getBuildStage()) {
case STANDALONE:
tmpStandalone.add(b);
b.buildStage = 1;
break;
case EXPANDING:
tmpExpanding.add(b);
b.buildStage = 2;
break;
}
} else {
postProcessing.add(b);
}
}
for (BuildingSlotBlock b : tmpStandalone) {
addToBuildList(b);
}
for (BuildingSlotBlock b : tmpExpanding) {
addToBuildList(b);
}
}
int seqId = 0;
for (SchematicEntity e : ((Blueprint) blueprint).entities) {
BuildingSlotEntity b = new BuildingSlotEntity();
b.schematic = e;
b.sequenceNumber = seqId;
if (!builtEntities.contains(seqId)) {
entityList.add(b);
} else {
postProcessing.add(b);
}
seqId++;
}
recomputeNeededItems();
}
use of buildcraft.core.builders.BuildingSlotEntity in project BuildCraft by BuildCraft.
the class BptBuilderBlueprint method deploy.
public void deploy() {
initialize();
for (List<BuildingSlotBlock> lb : buildList.values()) {
for (BuildingSlotBlock b : lb) {
if (b.mode == Mode.ClearIfInvalid) {
context.world.setBlockToAir(b.pos);
} else if (!b.schematic.doNotBuild()) {
b.stackConsumed = new LinkedList<>();
try {
for (ItemStack stk : b.getRequirements(context)) {
if (stk != null) {
b.stackConsumed.add(stk.copy());
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
b.writeToWorld(context);
}
}
}
for (BuildingSlotEntity e : entityList) {
e.stackConsumed = new LinkedList<>();
try {
for (ItemStack stk : e.getRequirements(context)) {
if (stk != null) {
e.stackConsumed.add(stk.copy());
}
}
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
e.writeToWorld(context);
}
for (List<BuildingSlotBlock> lb : buildList.values()) {
for (BuildingSlotBlock b : lb) {
if (b.mode != Mode.ClearIfInvalid) {
b.postProcessing(context);
}
}
}
for (BuildingSlotEntity e : entityList) {
e.postProcessing(context);
}
}
Aggregations