use of buildcraft.api.blueprints.SchematicBlock in project BuildCraft by BuildCraft.
the class SchematicFactoryBlock method loadSchematicFromWorldNBT.
@Override
protected SchematicBlock loadSchematicFromWorldNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException {
int blockId = nbt.getInteger("blockId");
Block b = registry.getBlockForId(blockId);
if (b == Blocks.AIR) {
SchematicBlock s = new SchematicBlock();
s.state = Blocks.AIR.getDefaultState();
return s;
} else {
SchematicBlock s = SchematicRegistry.INSTANCE.createSchematicBlock(b.getStateFromMeta(nbt.getInteger("blockMeta")));
if (s != null) {
s.readSchematicFromNBT(nbt, registry);
return s;
}
}
return null;
}
use of buildcraft.api.blueprints.SchematicBlock in project BuildCraft by BuildCraft.
the class SchematicRegistry method createSchematicBlock.
public SchematicBlock createSchematicBlock(IBlockState state) {
if (state == null) {
return null;
}
SchematicConstructor c = schematicBlocks.get(toStringKey(state));
if (c == null) {
return null;
}
try {
SchematicBlock s = (SchematicBlock) c.newInstance();
s.state = state;
return s;
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return null;
}
use of buildcraft.api.blueprints.SchematicBlock in project BuildCraft by BuildCraft.
the class BuildingSlotBlock method writeToWorld.
@Override
public boolean writeToWorld(IBuilderContext context) {
if (internalRequirementRemovalListener != null) {
internalRequirementRemovalListener.remove(this);
}
if (mode == Mode.ClearIfInvalid) {
if (!getSchematic().isAlreadyBuilt(context, pos)) {
context.world().sendBlockBreakProgress(pos.hashCode(), pos, -1);
if (BuildCraftBuilders.dropBrokenBlocks) {
BlockUtil.breakBlock((WorldServer) context.world(), pos, pos);
return false;
} else {
context.world().setBlockToAir(pos);
return true;
}
}
} else {
try {
getSchematic().placeInWorld(context, pos, stackConsumed);
// you're unable to break an API too much.
if (!getSchematic().isAlreadyBuilt(context, pos)) {
if (context.world().isAirBlock(pos)) {
return false;
} else if (!(getSchematic() instanceof SchematicBlock) || !context.world().getBlockState(pos).getBlock().isAssociatedBlock(((SchematicBlock) getSchematic()).state.getBlock())) {
BCLog.logger.warn("Placed block does not match expectations! Most likely a bug in BuildCraft or a supported mod. Removed mismatched block.");
IBlockState state = context.world().getBlockState(pos);
BCLog.logger.warn("Location: " + pos + " - Block: " + Block.REGISTRY.getNameForObject(state.getBlock()) + "@" + state);
context.world().removeTileEntity(pos);
context.world().setBlockToAir(pos);
return false;
} else {
return true;
}
}
// the stored requirements for anti-cheating purposes.
if (!context.world().isAirBlock(pos) && getSchematic().getBuildingPermission() == BuildingPermission.ALL && getSchematic() instanceof SchematicBlock) {
SchematicBlock sb = (SchematicBlock) getSchematic();
// Copy the old array of stored requirements.
ItemStack[] oldRequirementsArray = sb.storedRequirements;
List<ItemStack> oldRequirements = Arrays.asList(oldRequirementsArray);
sb.storedRequirements = new ItemStack[0];
sb.storeRequirements(context, pos);
for (ItemStack s : sb.storedRequirements) {
boolean contains = false;
for (ItemStack ss : oldRequirements) {
if (getSchematic().isItemMatchingRequirement(s, ss)) {
contains = true;
break;
}
}
if (!contains) {
BCLog.logger.warn("Blueprint has MISMATCHING REQUIREMENTS! Potential corrupted/hacked blueprint! Removed mismatched block.");
BCLog.logger.warn("Location: " + pos + " - ItemStack: " + s.toString());
context.world().removeTileEntity(pos);
context.world().setBlockToAir(pos);
return true;
}
}
// Restore the stored requirements.
sb.storedRequirements = oldRequirementsArray;
}
// Once the schematic has been written, we're going to issue
// calls
// to various functions, in particular updating the tile entity.
// If these calls issue problems, in order to avoid corrupting
// the world, we're logging the problem and setting the block to
// air.
TileEntity e = context.world().getTileEntity(pos);
if (e != null && e instanceof ITickable) {
((ITickable) e).update();
}
return true;
} catch (Throwable t) {
t.printStackTrace();
context.world().setBlockToAir(pos);
return false;
}
}
return false;
}
use of buildcraft.api.blueprints.SchematicBlock in project BuildCraft by BuildCraft.
the class Blueprint method readFromWorld.
@Override
public void readFromWorld(IBuilderContext context, TileEntity anchorTile, BlockPos pos) {
BptContext bptContext = (BptContext) context;
IBlockState state = anchorTile.getWorld().getBlockState(pos);
if (context.world().isAirBlock(pos)) {
// will make sure that they don't get recorded.
return;
}
SchematicBlock slot = SchematicRegistry.INSTANCE.createSchematicBlock(state);
if (slot == null) {
return;
}
BlockPos contextPos = pos.subtract(context.surroundingBox().min());
slot.state = state;
if (!SchematicRegistry.INSTANCE.isSupported(state)) {
return;
}
try {
slot.initializeFromObjectAt(context, pos);
slot.storeRequirements(context, pos);
set(contextPos, slot);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
switch(slot.getBuildingPermission()) {
case ALL:
break;
case CREATIVE_ONLY:
if (bptContext.readConfiguration.allowCreative) {
if (buildingPermission == BuildingPermission.ALL) {
buildingPermission = BuildingPermission.CREATIVE_ONLY;
}
} else {
set(contextPos, null);
}
break;
case NONE:
buildingPermission = BuildingPermission.NONE;
break;
}
}
use of buildcraft.api.blueprints.SchematicBlock 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();
}
Aggregations