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();
}
}
}
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);
}
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;
}
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()));
}
}
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);
}
}
}
Aggregations