use of com.ldtteam.structures.blueprints.v1.Blueprint 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.structures.blueprints.v1.Blueprint in project minecolonies by ldtteam.
the class ItemSupplyChestDeployer method canShipBePlaced.
/**
* Checks if the ship can be placed.
*
* @param world the world.
* @param pos the pos.
* @param ship the blueprint.
* @param placementErrorList the list of placement errors.
* @param placer the placer.
* @return true if so.
*/
public static boolean canShipBePlaced(@NotNull final World world, @NotNull final BlockPos pos, final Blueprint ship, @NotNull final List<PlacementError> placementErrorList, final PlayerEntity placer) {
if (MineColonies.getConfig().getServer().noSupplyPlacementRestrictions.get()) {
return true;
}
final int sizeX = ship.getSizeX();
final int sizeZ = ship.getSizeZ();
final int waterLevel = BlueprintTagUtils.getNumberOfGroundLevels(ship, DEFAULT_WATER_LEVELS);
final BlockPos zeroPos = pos.subtract(ship.getPrimaryBlockOffset());
for (int z = zeroPos.getZ(); z < zeroPos.getZ() + sizeZ; z++) {
for (int x = zeroPos.getX(); x < zeroPos.getX() + sizeX; x++) {
for (int y = zeroPos.getY(); y <= zeroPos.getY() + waterLevel + SCAN_HEIGHT; y++) {
if (y < zeroPos.getY() + waterLevel) {
checkFluidAndNotInColony(world, new BlockPos(x, y, z), placementErrorList, placer);
} else if (world.getBlockState(new BlockPos(x, y, z)).getMaterial().isSolid()) {
final PlacementError placementError = new PlacementError(PlacementError.PlacementErrorType.NEEDS_AIR_ABOVE, new BlockPos(x, y, z));
placementErrorList.add(placementError);
}
}
}
}
return placementErrorList.isEmpty();
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project minecolonies by ldtteam.
the class DecorationBuildRequestMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
if (colony == null) {
return;
}
final PlayerEntity player = ctxIn.getSender();
// Verify player has permission to change this huts settings
if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
return;
}
final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
if (entity instanceof TileEntityDecorationController) {
final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderBuildDecoration).filter(entry -> ((WorkOrderBuildDecoration) entry.getValue()).getSchematicLocation().equals(pos)).findFirst();
if (wo.isPresent()) {
colony.getWorkManager().removeWorkOrder(wo.get().getKey());
return;
}
int difference = 0;
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, new PlacementSettings(), true);
final Blueprint blueprint = structure.getBluePrint();
if (blueprint != null) {
final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
if (structureState != null) {
if (!(structureState.getBlock() instanceof BlockDecorationController)) {
Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
return;
}
final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
if (structureRotation <= worldRotation) {
difference = worldRotation - structureRotation;
} else {
difference = 4 + worldRotation - structureRotation;
}
}
}
final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
final WorkOrderBuildDecoration order = new WorkOrderBuildDecoration(name + level, name + level, difference, pos, state.getValue(BlockDecorationController.MIRROR));
if (level != ((TileEntityDecorationController) entity).getTier()) {
order.setLevelUp();
}
colony.getWorkManager().addWorkOrder(order, false);
}
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project minecolonies by ldtteam.
the class ClientEventHandler method renderWorldLastEvent.
/**
* Used to catch the renderWorldLastEvent in order to draw the debug nodes for pathfinding.
*
* @param event the catched event.
*/
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event) {
Pathfinding.debugDraw(event.getPartialTicks(), event.getMatrixStack());
final Blueprint structure = Settings.instance.getActiveStructure();
final ClientWorld world = Minecraft.getInstance().level;
final PlayerEntity player = Minecraft.getInstance().player;
if (structure != null) {
handleRenderStructure(event, world, player);
}
if (player.getMainHandItem().getItem() == ModItems.scepterGuard) {
handleRenderScepterGuard(event, world, player);
} else if (player.getMainHandItem().getItem() == ModItems.bannerRallyGuards) {
handleRenderBannerRallyGuards(event, world, player);
} else if (player.getMainHandItem().getItem() == com.ldtteam.structurize.items.ModItems.buildTool.get()) {
handleRenderBuildTool(event, world, player);
} else {
alreadyRequestedStructures.clear();
}
DebugRendererChunkBorder.renderWorldLastEvent(event);
renderBuffer.endBatch();
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project minecolonies by Minecolonies.
the class EventStructureManager method spawnTemporaryStructure.
/**
* Spawns the given structure at the blockpos and saves a backup for the previous blocks.
*
* @param structure the structure to spawn.
* @param eventID the id of the event.
*/
@Override
public boolean spawnTemporaryStructure(final Blueprint structure, final String schematicPath, final BlockPos targetSpawnPoint, final int eventID, final int rotations, final Mirror mirror) {
if (eventManager.getEventByID(eventID) == null) {
return false;
}
final World world = colony.getWorld();
final int y = BlueprintTagUtils.getNumberOfGroundLevels(structure, 4) - 1;
final BlockPos spawnPos = targetSpawnPoint.offset(0, -y, 0).offset(structure.getPrimaryBlockOffset());
final BlockPos zeroPos = spawnPos.subtract(structure.getPrimaryBlockOffset());
final BlockPos cornerPos = new BlockPos(zeroPos.getX() + structure.getSizeX() - 1, zeroPos.getY() + structure.getSizeY(), zeroPos.getZ() + structure.getSizeZ() - 1);
final BlockPos anchor = new BlockPos(zeroPos.getX() + structure.getSizeX() / 2, zeroPos.getY(), zeroPos.getZ() + structure.getSizeZ() / 2);
final String backupPath = Structures.SCHEMATICS_PREFIX + "/" + STRUCTURE_BACKUP_FOLDER + "/" + colony.getID() + "/" + colony.getDimension().location().getNamespace() + colony.getDimension().location().getPath() + "/" + anchor;
if (!ItemScanTool.saveStructureOnServer(world, zeroPos, cornerPos, backupPath, false)) {
// No structure spawn if we didn't successfully save the surroundings before
Log.getLogger().info("Failed to save schematics for event");
return false;
}
backupSchematics.put(anchor, eventID);
CreativeRaiderStructureHandler.loadAndPlaceStructureWithRotation(world, schematicPath, spawnPos, BlockPosUtil.getRotationFromRotations(rotations), mirror, true, colony.getID(), (IColonyRaidEvent) eventManager.getEventByID(eventID), null);
return true;
}
Aggregations