use of com.ldtteam.structurize.management.StructureName in project Structurize by ldtteam.
the class ItemScanTool method saveStructureOnServer.
/**
* Save a structure on the server.
*
* @param world the world.
* @param from the start position.
* @param to the end position.
* @param name the name.
* @param saveEntities whether to scan in entities
* @return true if succesful.
*/
public static boolean saveStructureOnServer(@NotNull final World world, @NotNull final BlockPos from, @NotNull final BlockPos to, final String name, final boolean saveEntities) {
final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));
final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
final BlockPos size = blockpos1.subtract(blockpos).offset(1, 1, 1);
if (size.getX() * size.getY() * size.getZ() > Structurize.getConfig().getServer().schematicBlockLimit.get()) {
Log.getLogger().warn("Saving too large schematic for:" + name);
}
final String prefix = "cache";
final String fileName;
if (name == null || name.isEmpty()) {
fileName = LanguageHandler.format("item.sceptersteel.scanformat");
} else {
fileName = name;
}
final StructureName structureName = new StructureName(prefix, "backup", fileName);
final List<File> folder = StructureLoadingUtils.getCachedSchematicsFolders();
if (folder == null || folder.isEmpty()) {
Log.getLogger().warn("Unable to save schematic in cache since no folder was found.");
return false;
}
final Blueprint bp = BlueprintUtil.createBlueprint(world, blockpos, saveEntities, (short) size.getX(), (short) size.getY(), (short) size.getZ(), name, Optional.empty());
final File file = new File(folder.get(0), structureName.toString() + Structures.SCHEMATIC_EXTENSION_NEW);
Utils.checkDirectory(file.getParentFile());
try (OutputStream outputstream = new FileOutputStream(file)) {
CompressedStreamTools.writeCompressed(BlueprintUtil.writeBlueprintToNBT(bp), outputstream);
} catch (final Exception e) {
return false;
}
return true;
}
use of com.ldtteam.structurize.management.StructureName in project Structurize by ldtteam.
the class StructureLoadingUtils method getStream.
/**
* get a InputStream for a give structureName.
* <p>
* Look into the following director (in order):
* - scan
* - cache
* - schematics folder
* - jar
* It should be the exact opposite that the way used to build the list.
* <p>
* Suppressing Sonar Rule squid:S2095
* This rule enforces "Close this InputStream"
* But in this case the rule does not apply because
* We are returning the stream and that is reasonable
*
* @param structureName name of the structure to load
* @return the input stream or null
*/
@SuppressWarnings(RESOURCES_SHOULD_BE_CLOSED)
@Nullable
public static InputStream getStream(final String structureName) {
final StructureName sn = new StructureName(structureName);
InputStream inputstream = null;
if (Structures.SCHEMATICS_CACHE.equals(sn.getPrefix())) {
for (final File cachedFile : StructureLoadingUtils.getCachedSchematicsFolders()) {
final InputStream stream = StructureLoadingUtils.getStreamFromFolder(cachedFile, structureName);
if (stream != null) {
return stream;
}
}
} else if (Structures.SCHEMATICS_SCAN.equals(sn.getPrefix()) && FMLEnvironment.dist == Dist.CLIENT) {
for (final File cachedFile : StructureLoadingUtils.getClientSchematicsFolders()) {
final InputStream stream = StructureLoadingUtils.getStreamFromFolder(cachedFile, structureName);
if (stream != null) {
return stream;
}
}
} else if (!Structures.SCHEMATICS_PREFIX.equals(sn.getPrefix())) {
return null;
} else {
// Look in the folder first
inputstream = StructureLoadingUtils.getStreamFromFolder(Structurize.proxy.getSchematicsFolder(), structureName);
if (inputstream == null && !Structurize.getConfig().getServer().ignoreSchematicsFromJar.get()) {
inputstream = getStreamFromJar(structureName);
}
}
return inputstream;
}
use of com.ldtteam.structurize.management.StructureName in project minecolonies by ldtteam.
the class EventStructureManager method loadBackupForEvent.
@Override
public void loadBackupForEvent(final int eventID) {
final Iterator<Map.Entry<BlockPos, Integer>> iterator = backupSchematics.entrySet().iterator();
while (iterator.hasNext()) {
final Map.Entry<BlockPos, Integer> entry = iterator.next();
if (entry.getValue() == eventID) {
final String oldBackupPath = String.valueOf(colony.getID()) + colony.getDimension() + entry.getKey();
String fileName = new StructureName("cache", "backup", Structures.SCHEMATICS_PREFIX + "/" + STRUCTURE_BACKUP_FOLDER).toString() + "/" + String.valueOf(colony.getID()) + "/" + colony.getDimension().location().getNamespace() + colony.getDimension().location().getPath() + "/" + entry.getKey();
// TODO: remove compat for colony.getDimension()-based file names after sufficient time has passed from PR#6305
if (CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(colony.getWorld(), fileName, entry.getKey(), Rotation.NONE, Mirror.NONE, true, null) == null) {
fileName = new StructureName("cache", "backup", Structures.SCHEMATICS_PREFIX + STRUCTURE_BACKUP_FOLDER).toString() + oldBackupPath;
CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(colony.getWorld(), fileName, entry.getKey(), Rotation.NONE, Mirror.NONE, true, null);
}
try {
Structurize.proxy.getSchematicsFolder().toPath().resolve(fileName + SCHEMATIC_EXTENSION_NEW).toFile().delete();
} catch (Exception e) {
Log.getLogger().info("Minor issue: Failed at deleting a backup schematic at " + fileName, e);
}
iterator.remove();
}
}
}
use of com.ldtteam.structurize.management.StructureName in project minecolonies by ldtteam.
the class WorkOrderBuildDecoration method read.
/**
* Read the WorkOrder data from the CompoundNBT.
*
* @param compound NBT Tag compound.
*/
@Override
public void read(@NotNull final CompoundNBT compound, final IWorkManager manager) {
super.read(compound, manager);
final StructureName sn = new StructureName(compound.getString(TAG_SCHEMATIC_NAME));
structureName = sn.toString();
workOrderName = compound.getString(TAG_WORKORDER_NAME);
cleared = compound.getBoolean(TAG_IS_CLEARED);
buildingRotation = compound.getInt(TAG_BUILDING_ROTATION);
requested = compound.getBoolean(TAG_IS_REQUESTED);
isBuildingMirrored = compound.getBoolean(TAG_IS_MIRRORED);
amountOfRes = compound.getInt(TAG_AMOUNT_OF_RES);
levelUp = compound.getBoolean(TAG_LEVEL);
}
use of com.ldtteam.structurize.management.StructureName in project minecolonies by ldtteam.
the class WindowBuildBuilding method updateResources.
/**
* Clears and resets/updates all resources.
*/
private void updateResources() {
if (stylesDropDownList.getSelectedIndex() == -1) {
return;
}
final World world = Minecraft.getInstance().level;
resources.clear();
final IBuildingView parentBuilding = building.getColony().getBuilding(building.getParent());
int nextLevel = building.getBuildingLevel();
if (building.getBuildingLevel() < building.getBuildingMaxLevel() && (parentBuilding == null || building.getBuildingLevel() < parentBuilding.getBuildingLevel())) {
nextLevel = building.getBuildingLevel() + 1;
}
final TileEntity tile = world.getBlockEntity(building.getID());
String schematicName = building.getSchematicName();
if (tile instanceof IBlueprintDataProvider) {
if (!((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
schematicName = ((IBlueprintDataProvider) tile).getSchematicName().replaceAll("\\d$", "");
}
}
final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), schematicName + nextLevel);
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, building.getPosition(), sn.toString(), new PlacementSettings(), true);
final String md5 = Structures.getMD5(sn.toString());
if (!structure.hasBluePrint() || !structure.isCorrectMD5(md5)) {
if (!structure.hasBluePrint()) {
Log.getLogger().info("Template structure " + sn + " missing");
} else {
Log.getLogger().info("structure " + sn + " md5 error");
}
Log.getLogger().info("Request To Server for structure " + sn);
if (ServerLifecycleHooks.getCurrentServer() == null) {
com.ldtteam.structurize.Network.getNetwork().sendToServer(new SchematicRequestMessage(sn.toString()));
return;
} else {
Log.getLogger().error("WindowMinecoloniesBuildTool: Need to download schematic on a standalone client/server. This should never happen", new Exception());
}
}
if (!structure.hasBluePrint()) {
findPaneOfTypeByID(BUTTON_BUILD, Button.class).hide();
findPaneOfTypeByID(BUTTON_REPAIR, Button.class).hide();
findPaneOfTypeByID(BUTTON_PICKUP_BUILDING, Button.class).show();
return;
}
structure.getBluePrint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(building.getRotation()), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE, world);
StructurePlacer placer = new StructurePlacer(structure);
StructurePhasePlacementResult result;
BlockPos progressPos = NULL_POS;
do {
result = placer.executeStructureStep(world, null, progressPos, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.and((info, pos, handler) -> false)), true);
progressPos = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
addNeededResource(stack, stack.getCount());
}
} while (result != null && result.getBlockResult().getResult() != BlockPlacementResult.Result.FINISHED);
window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
updateResourceList();
}
Aggregations