use of buildcraft.api.blueprints.SchematicBlockBase in project BuildCraft by BuildCraft.
the class Blueprint method saveContents.
@Override
public void saveContents(NBTTagCompound nbt) {
NBTTagCompound nbtContents = new NBTTagCompound();
for (BlockPos pos : BlockPos.getAllInBox(BlockPos.ORIGIN, size.subtract(Utils.POS_ONE))) {
SchematicBlockBase schematic = null;
NBTTagCompound cpt = new NBTTagCompound();
try {
schematic = get(pos);
if (schematic != null) {
schematic.idsToBlueprint(mapping);
schematic.writeSchematicToNBT(cpt, mapping);
/* We don't use the index of the current for loop because we shouldn't rely on the behaviour of
* BlockPos.getAllInBox */
nbtContents.setTag(StringUtilBC.blockPosToShortString(pos), cpt);
}
} catch (Throwable t) {
CrashReport crash;
if (t instanceof ReportedException) {
crash = ((ReportedException) t).getCrashReport();
} else {
crash = new CrashReport("Failed to save the contents of a blueprint!", t);
}
CrashReportCategory cat = crash.makeCategory("Block Being Saved");
cat.addCrashSection("Block Position (In schematic)", pos);
cat.addCrashSection("Schematic type", schematic == null ? "~~NULL~~" : schematic.getClass());
mapping.addToCrashReport(crash.makeCategory("Mapping Registry"));
throw new ReportedException(crash);
}
}
nbt.setTag("contents", nbtContents);
NBTTagList entitiesNBT = new NBTTagList();
for (SchematicEntity s : entities) {
NBTTagCompound subNBT = new NBTTagCompound();
s.idsToBlueprint(mapping);
s.writeSchematicToNBT(subNBT, mapping);
entitiesNBT.appendTag(subNBT);
}
nbt.setTag("entities", entitiesNBT);
NBTTagCompound contextNBT = new NBTTagCompound();
mapping.write(contextNBT);
nbt.setTag("idMapping", contextNBT);
}
use of buildcraft.api.blueprints.SchematicBlockBase in project BuildCraft by BuildCraft.
the class BptBuilderTemplate 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)) {
if (blueprint.excavate) {
for (BlockPos bptOffset : BlockPos.getAllInBox(bptMin, bptMax)) {
BlockPos pointWorldOffset = worldOffset.add(bptOffset);
SchematicBlockBase slot = blueprint.get(bptOffset);
if (slot == null && !isLocationUsed(pointWorldOffset)) {
BuildingSlotBlock b = new BuildingSlotBlock();
b.schematic = null;
b.pos = pointWorldOffset;
b.mode = Mode.ClearIfInvalid;
b.buildStage = 0;
clearList.add(b);
}
}
}
for (BlockPos bptOffset : BlockPos.getAllInBox(bptMin, bptMax)) {
BlockPos pointWorldOffset = worldOffset.add(bptOffset);
SchematicBlockBase slot = blueprint.get(bptOffset);
if (slot != null && !isLocationUsed(pointWorldOffset)) {
BuildingSlotBlock b = new BuildingSlotBlock();
b.schematic = slot;
b.pos = pointWorldOffset;
b.mode = Mode.Build;
b.buildStage = 1;
buildList.add(b);
}
}
}
iteratorBuild = new BuildingSlotIterator(buildList);
iteratorClear = new BuildingSlotIterator(clearList);
}
use of buildcraft.api.blueprints.SchematicBlockBase in project BuildCraft by BuildCraft.
the class Blueprint method loadSingleSchematicFromNBT.
private void loadSingleSchematicFromNBT(BlockPos pos, NBTTagCompound cpt) {
if (cpt.hasKey("blockId")) {
Block block;
try {
block = mapping.getBlockForId(cpt.getInteger("blockId"));
} catch (MappingNotFoundException e) {
block = null;
isComplete = false;
}
if (block != null) {
int meta = cpt.getInteger("blockMeta");
SchematicBlockBase schematic = SchematicRegistry.INSTANCE.createSchematicBlock(block.getStateFromMeta(meta));
if (schematic != null) {
schematic.readSchematicFromNBT(cpt, mapping);
if (!schematic.doNotUse()) {
schematic.idsToWorld(mapping);
switch(schematic.getBuildingPermission()) {
case ALL:
break;
case CREATIVE_ONLY:
if (buildingPermission == BuildingPermission.ALL) {
buildingPermission = BuildingPermission.CREATIVE_ONLY;
}
break;
case NONE:
buildingPermission = BuildingPermission.NONE;
break;
}
} else {
schematic = null;
isComplete = false;
}
}
set(pos, schematic);
} else {
set(pos, null);
isComplete = false;
}
} else {
set(pos, null);
}
}
Aggregations