use of buildcraft.builders.snapshot.Blueprint in project BuildCraft by BuildCraft.
the class TileBuilder method updateSnapshot.
private void updateSnapshot(boolean canGetFacing) {
Optional.ofNullable(getBuilder()).ifPresent(SnapshotBuilder::cancel);
if (snapshot != null && getCurrentBasePos() != null) {
snapshotType = snapshot.getType();
if (canGetFacing) {
rotation = Arrays.stream(Rotation.values()).filter(r -> r.rotate(snapshot.facing) == world.getBlockState(pos).getValue(BlockBCBase_Neptune.PROP_FACING)).findFirst().orElse(null);
}
if (snapshot.getType() == EnumSnapshotType.TEMPLATE) {
templateBuildingInfo = ((Template) snapshot).new BuildingInfo(getCurrentBasePos(), rotation);
}
if (snapshot.getType() == EnumSnapshotType.BLUEPRINT) {
blueprintBuildingInfo = ((Blueprint) snapshot).new BuildingInfo(getCurrentBasePos(), rotation);
}
currentBox = Optional.ofNullable(getBuildingInfo()).map(buildingInfo -> buildingInfo.box).orElse(null);
Optional.ofNullable(getBuilder()).ifPresent(SnapshotBuilder::updateSnapshot);
} else {
snapshotType = null;
rotation = null;
templateBuildingInfo = null;
blueprintBuildingInfo = null;
currentBox = null;
}
if (currentBox == null) {
currentBox = new Box();
}
}
use of buildcraft.builders.snapshot.Blueprint in project BuildCraft by BuildCraft.
the class TileReplacer method update.
@Override
public void update() {
if (world.isRemote) {
return;
}
if (!invSnapshot.getStackInSlot(0).isEmpty() && !invSchematicFrom.getStackInSlot(0).isEmpty() && !invSchematicTo.getStackInSlot(0).isEmpty()) {
Header header = BCBuildersItems.snapshot.getHeader(invSnapshot.getStackInSlot(0));
if (header != null) {
Snapshot snapshot = GlobalSavedDataSnapshots.get(world).getSnapshot(header.key);
if (snapshot instanceof Blueprint) {
Blueprint blueprint = (Blueprint) snapshot;
try {
ISchematicBlock from = SchematicBlockManager.readFromNBT(NBTUtilBC.getItemData(invSchematicFrom.getStackInSlot(0)).getCompoundTag(ItemSchematicSingle.NBT_KEY));
ISchematicBlock to = SchematicBlockManager.readFromNBT(NBTUtilBC.getItemData(invSchematicTo.getStackInSlot(0)).getCompoundTag(ItemSchematicSingle.NBT_KEY));
Blueprint newBlueprint = blueprint.copy();
newBlueprint.replace(from, to);
newBlueprint.computeKey();
GlobalSavedDataSnapshots.get(world).addSnapshot(newBlueprint);
invSnapshot.setStackInSlot(0, BCBuildersItems.snapshot.getUsed(EnumSnapshotType.BLUEPRINT, new Header(blueprint.key, getOwner().getId(), new Date(), header.name)));
invSchematicFrom.setStackInSlot(0, ItemStack.EMPTY);
invSchematicTo.setStackInSlot(0, ItemStack.EMPTY);
} catch (InvalidInputDataException e) {
e.printStackTrace();
}
}
}
}
}
use of buildcraft.builders.snapshot.Blueprint in project BuildCraft by BuildCraft.
the class TileArchitectTable method finishScanning.
private void finishScanning() {
IBlockState thisState = getCurrentStateForBlock(BCBuildersBlocks.architect);
if (thisState == null) {
return;
}
EnumFacing facing = thisState.getValue(BlockArchitectTable.PROP_FACING);
Snapshot snapshot = Snapshot.create(snapshotType);
snapshot.size = box.size();
snapshot.facing = facing;
snapshot.offset = box.min().subtract(pos.offset(facing.getOpposite()));
if (snapshot instanceof Template) {
((Template) snapshot).data = templateScannedBlocks;
}
if (snapshot instanceof Blueprint) {
((Blueprint) snapshot).palette.addAll(blueprintScannedPalette);
((Blueprint) snapshot).data = blueprintScannedData;
((Blueprint) snapshot).entities.addAll(blueprintScannedEntities);
}
snapshot.computeKey();
GlobalSavedDataSnapshots.get(world).addSnapshot(snapshot);
ItemStack stackIn = invSnapshotIn.getStackInSlot(0);
stackIn.setCount(stackIn.getCount() - 1);
if (stackIn.getCount() == 0) {
stackIn = ItemStack.EMPTY;
}
invSnapshotIn.setStackInSlot(0, stackIn);
invSnapshotOut.setStackInSlot(0, BCBuildersItems.snapshot.getUsed(snapshotType, new Header(snapshot.key, getOwner().getId(), new Date(), name)));
templateScannedBlocks = null;
blueprintScannedData = null;
blueprintScannedEntities.clear();
boxIterator = null;
sendNetworkUpdate(NET_RENDER_DATA);
AdvancementUtil.unlockAdvancement(getOwner().getId(), ADVANCEMENT);
}
Aggregations