Search in sources :

Example 16 with Blueprint

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;
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) StructureName(com.ldtteam.structurize.management.StructureName) BlockPos(net.minecraft.util.math.BlockPos) File(java.io.File)

Example 17 with Blueprint

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();
}
Also used : PlacementError(com.ldtteam.structurize.placement.handlers.placement.PlacementError) BlockPos(net.minecraft.util.math.BlockPos) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 18 with Blueprint

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);
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) Action(com.minecolonies.api.colony.permissions.Action) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) RegistryKey(net.minecraft.util.RegistryKey) Map(java.util.Map) Log(com.minecolonies.api.util.Log) BlockState(net.minecraft.block.BlockState) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) LogicalSide(net.minecraftforge.fml.LogicalSide) IMessage(com.minecolonies.api.network.IMessage) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Registry(net.minecraft.util.registry.Registry) Nullable(org.jetbrains.annotations.Nullable) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) IColony(com.minecolonies.api.colony.IColony) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 19 with Blueprint

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();
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) ClientWorld(net.minecraft.client.world.ClientWorld) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 20 with Blueprint

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;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Aggregations

Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)37 BlockPos (net.minecraft.util.math.BlockPos)23 BlockState (net.minecraft.block.BlockState)13 StructureName (com.ldtteam.structurize.management.StructureName)8 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)8 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 TileEntity (net.minecraft.tileentity.TileEntity)6 Nullable (org.jetbrains.annotations.Nullable)6 BlockInfo (com.ldtteam.structurize.util.BlockInfo)5 NotNull (org.jetbrains.annotations.NotNull)5 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)4 World (net.minecraft.world.World)4 Optional (java.util.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)2 PlacementError (com.ldtteam.structurize.placement.handlers.placement.PlacementError)2 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 IColony (com.minecolonies.api.colony.IColony)2