Search in sources :

Example 21 with StructureName

use of com.ldtteam.structurize.management.StructureName in project minecolonies by Minecolonies.

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();
        }
    }
}
Also used : StructureName(com.ldtteam.structurize.management.StructureName) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with StructureName

use of com.ldtteam.structurize.management.StructureName in project minecolonies by Minecolonies.

the class WorkManager method addWorkOrder.

/**
 * Adds work order to the work manager.
 *
 * @param order          Order adding.
 * @param readingFromNbt if being read from NBT.
 */
@Override
public void addWorkOrder(@NotNull final IWorkOrder order, final boolean readingFromNbt) {
    dirty = true;
    if (!(order instanceof WorkOrderMiner)) {
        for (final IWorkOrder or : workOrders.values()) {
            if (or.getLocation().equals(order.getLocation()) && or.getStructureName().equals(order.getStructureName())) {
                Log.getLogger().warn("Avoiding adding duplicate workOrder");
                removeWorkOrder(or);
                break;
            }
        }
        if (!readingFromNbt && !isWorkOrderWithinColony(order)) {
            MessageUtils.format(OUT_OF_COLONY, order.getDisplayName(), order.getLocation().getX(), order.getLocation().getZ()).sendTo(colony).forAllPlayers();
            return;
        }
    }
    if (order.getID() == 0) {
        topWorkOrderId++;
        order.setID(topWorkOrderId);
    }
    if (!readingFromNbt) {
        final StructureName structureName = new StructureName(order.getStructureName());
        if (order instanceof WorkOrderBuilding) {
            final int level = order.getTargetLevel();
            AdvancementUtils.TriggerAdvancementPlayersForColony(colony, player -> AdvancementTriggers.CREATE_BUILD_REQUEST.trigger(player, structureName, level));
        } else if (order instanceof WorkOrderDecoration) {
            AdvancementUtils.TriggerAdvancementPlayersForColony(colony, player -> AdvancementTriggers.CREATE_BUILD_REQUEST.trigger(player, structureName, 0));
        }
    }
    workOrders.put(order.getID(), order);
    order.onAdded(colony, readingFromNbt);
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) java.util(java.util) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) CompoundNBT(net.minecraft.nbt.CompoundNBT) CLOSE_COLONY_CAP(com.minecolonies.coremod.MineColonies.CLOSE_COLONY_CAP) ICitizenData(com.minecolonies.api.colony.ICitizenData) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) AdvancementUtils(com.minecolonies.coremod.util.AdvancementUtils) Log(com.minecolonies.api.util.Log) ListNBT(net.minecraft.nbt.ListNBT) MessageUtils(com.minecolonies.api.util.MessageUtils) StructureName(com.ldtteam.structurize.management.StructureName) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability) Tuple(net.minecraft.util.Tuple) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) AdvancementTriggers(com.minecolonies.api.advancements.AdvancementTriggers) NBT(net.minecraftforge.common.util.Constants.NBT) IColony(com.minecolonies.api.colony.IColony) OUT_OF_COLONY(com.minecolonies.api.util.constant.TranslationConstants.OUT_OF_COLONY) NotNull(org.jetbrains.annotations.NotNull) IWorkManager(com.minecolonies.api.colony.workorders.IWorkManager) IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) StructureName(com.ldtteam.structurize.management.StructureName)

Example 23 with StructureName

use of com.ldtteam.structurize.management.StructureName in project minecolonies by Minecolonies.

the class WorkOrderBuilding method create.

public static WorkOrderBuilding create(@NotNull final WorkOrderType type, @NotNull final IBuilding building) {
    int targetLevel = building.getBuildingLevel();
    switch(type) {
        case BUILD:
            targetLevel = 1;
            break;
        case UPGRADE:
            targetLevel++;
            break;
        case REMOVE:
            targetLevel = 0;
            break;
    }
    String schematicName;
    final int targetSchematicLevel = type == WorkOrderType.REMOVE ? building.getBuildingLevel() : targetLevel;
    final TileEntity buildingTE = building.getColony().getWorld().getBlockEntity(building.getID());
    if (buildingTE instanceof AbstractTileEntityColonyBuilding) {
        if (!((AbstractTileEntityColonyBuilding) buildingTE).getSchematicName().isEmpty()) {
            schematicName = ((AbstractTileEntityColonyBuilding) buildingTE).getSchematicName().replaceAll("\\d$", "") + targetSchematicLevel;
        } else {
            schematicName = building.getSchematicName() + targetSchematicLevel;
        }
    } else {
        schematicName = building.getSchematicName() + targetSchematicLevel;
    }
    String structureName = new StructureName(Structures.SCHEMATICS_PREFIX, building.getStyle(), schematicName).toString();
    WorkOrderBuilding wo = new WorkOrderBuilding(structureName, building.getBuildingType().getTranslationKey(), type, building.getID(), building.getRotation(), building.getTileEntity() == null ? building.isMirrored() : building.getTileEntity().isMirrored(), building.getBuildingLevel(), targetLevel);
    wo.setCustomName(building);
    return wo;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) StructureName(com.ldtteam.structurize.management.StructureName)

Example 24 with StructureName

use of com.ldtteam.structurize.management.StructureName in project minecolonies by Minecolonies.

the class WorkOrderBuilding method onCompleted.

@Override
public void onCompleted(final IColony colony, ICitizenData citizen) {
    super.onCompleted(colony, citizen);
    final StructureName structureName = new StructureName(this.getStructureName());
    if (getWorkOrderType() != WorkOrderType.REMOVE) {
        AdvancementUtils.TriggerAdvancementPlayersForColony(colony, player -> AdvancementTriggers.COMPLETE_BUILD_REQUEST.trigger(player, structureName, this.getTargetLevel()));
    }
}
Also used : StructureName(com.ldtteam.structurize.management.StructureName)

Example 25 with StructureName

use of com.ldtteam.structurize.management.StructureName in project minecolonies by Minecolonies.

the class BuildToolPasteMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final StructureName sn = new StructureName(structureName);
    final ServerPlayerEntity player = ctxIn.getSender();
    if (!Structures.hasMD5(sn)) {
        MessageUtils.format(new StringTextComponent("Can not build " + workOrderName + ": schematic missing!")).sendTo(player);
        return;
    }
    if (player.isCreative()) {
        if (isHut) {
            handleHut(CompatibilityUtils.getWorldFromEntity(player), player, sn, rotation, pos, mirror, state, complete);
            CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(player.level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, player);
            @Nullable final IBuilding building = IColonyManager.getInstance().getBuilding(CompatibilityUtils.getWorldFromEntity(player), pos);
            if (building != null) {
                final WorkOrderBuilding workOrder = WorkOrderBuilding.create(WorkOrderType.BUILD, building);
                ConstructionTapeHelper.removeConstructionTape(workOrder, CompatibilityUtils.getWorldFromEntity(player));
            }
        } else {
            StructurePlacementUtils.loadAndPlaceStructureWithRotation(ctxIn.getSender().level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, ctxIn.getSender());
        }
    } else if (structureName.contains("supply")) {
        if (player.getStats().getValue(Stats.ITEM_USED.get(ModItems.supplyChest)) > 0 && !MineColonies.getConfig().getServer().allowInfiniteSupplyChests.get() && !isFreeInstantPlacementMH(player)) {
            MessageUtils.format(WARNING_SUPPLY_CHEST_ALREADY_PLACED).sendTo(player);
            return;
        }
        Predicate<ItemStack> searchPredicate = stack -> !stack.isEmpty();
        if (structureName.contains("supplyship")) {
            searchPredicate = searchPredicate.and(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, new ItemStack(ModItems.supplyChest), true, false));
        }
        if (structureName.contains("supplycamp")) {
            searchPredicate = searchPredicate.and(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, new ItemStack(ModItems.supplyCamp), true, false));
        }
        if (isFreeInstantPlacementMH(player)) {
            searchPredicate = searchPredicate.and(stack -> stack.hasTag() && stack.getTag().get(PLACEMENT_NBT) != null && stack.getTag().getString(PLACEMENT_NBT).equals(INSTANT_PLACEMENT));
        }
        final int slot = InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(new InvWrapper(player.inventory), searchPredicate);
        if (slot != -1 && !ItemStackUtils.isEmpty(player.inventory.removeItemNoUpdate(slot))) {
            if (player.getStats().getValue(Stats.ITEM_USED.get(ModItems.supplyChest)) < 1) {
                MessageUtils.format(PROGRESS_SUPPLY_CHEST_PLACED).sendTo(player);
                player.awardStat(Stats.ITEM_USED.get(ModItems.supplyChest), 1);
                AdvancementTriggers.PLACE_SUPPLY.trigger(player);
            }
            CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(player.level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, player);
        } else {
            MessageUtils.format(WARNING_REMOVING_SUPPLY_CHEST).sendTo(player);
        }
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) StructureName(com.ldtteam.structurize.management.StructureName) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Predicate(java.util.function.Predicate)

Aggregations

StructureName (com.ldtteam.structurize.management.StructureName)43 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)14 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)10 BlockPos (net.minecraft.util.math.BlockPos)9 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)7 Nullable (org.jetbrains.annotations.Nullable)6 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)5 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)5 TileEntity (net.minecraft.tileentity.TileEntity)5 DropDownList (com.ldtteam.blockout.views.DropDownList)4 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)4 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)4 IColonyView (com.minecolonies.api.colony.IColonyView)4 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 StringTextComponent (net.minecraft.util.text.StringTextComponent)4 Button (com.ldtteam.blockout.controls.Button)3 IAltersBuildingFootprint (com.minecolonies.api.colony.buildings.modules.IAltersBuildingFootprint)3 Log (com.minecolonies.api.util.Log)3 Predicate (java.util.function.Predicate)3