Search in sources :

Example 36 with StructureName

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

the class AbstractSchematicProvider method serializeNBT.

@Override
public CompoundNBT serializeNBT() {
    final CompoundNBT compound = new CompoundNBT();
    BlockPosUtil.write(compound, TAG_LOCATION, location);
    final StructureName structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + buildingLevel);
    if (Structures.hasMD5(structureName)) {
        compound.putString(TAG_SCHEMATIC_MD5, Structures.getMD5(structureName.toString()));
    }
    compound.putInt(TAG_SCHEMATIC_LEVEL, buildingLevel);
    compound.putString(TAG_STYLE, style);
    compound.putBoolean(TAG_MIRROR, isBuildingMirrored);
    getCorners();
    BlockPosUtil.write(compound, TAG_CORNER1, this.lowerCorner);
    BlockPosUtil.write(compound, TAG_CORNER2, this.higherCorner);
    compound.putInt(TAG_HEIGHT, this.height);
    compound.putInt(TAG_ROTATION, getRotation());
    compound.putBoolean(TAG_DECONSTRUCTED, isDeconstructed);
    BlockPosUtil.write(compound, TAG_PARENT_SCHEM, parentSchematic);
    BlockPosUtil.writePosListToNBT(compound, TAG_CHILD_SCHEM, new ArrayList<>(childSchematics));
    return compound;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) StructureName(com.ldtteam.structurize.management.StructureName)

Example 37 with StructureName

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

the class AbstractSchematicProvider method getRotation.

@Override
public int getRotation() {
    if (cachedRotation != -1) {
        return cachedRotation;
    }
    final StructureName structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + Math.max(1, buildingLevel));
    try {
        final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), structureName.toString(), 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 AbstractBlockHut) || !(colony.getWorld().getBlockState(this.location).getBlock() instanceof AbstractBlockHut)) {
                    Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", structureName.toString()));
                    return 0;
                }
                final int structureRotation = structureState.getValue(AbstractBlockHut.FACING).get2DDataValue();
                final int worldRotation = colony.getWorld().getBlockState(this.location).getValue(AbstractBlockHut.FACING).get2DDataValue();
                if (structureRotation <= worldRotation) {
                    cachedRotation = worldRotation - structureRotation;
                } else {
                    cachedRotation = 4 + worldRotation - structureRotation;
                }
                return cachedRotation;
            }
        }
    } catch (Exception e) {
        Log.getLogger().error(String.format("Failed to get rotation for %s: ", structureName.toString()), e);
        return 0;
    }
    return 0;
}
Also used : BlockState(net.minecraft.block.BlockState) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) StructureName(com.ldtteam.structurize.management.StructureName) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) IAltersBuildingFootprint(com.minecolonies.api.colony.buildings.modules.IAltersBuildingFootprint) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 38 with StructureName

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

the class AbstractSchematicProvider method unsafeUpdateTEDataFromSchematic.

/**
 * Load the schematic data from the TE schematic name, if it's a reattempt, calculate the name from the building (backup).
 * Might throw exceptions if data is invalid.
 */
private void unsafeUpdateTEDataFromSchematic(final TileEntityColonyBuilding te) {
    final String structureName;
    if (te.getSchematicName().isEmpty()) {
        structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + Math.max(1, buildingLevel)).toString();
    } else {
        structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, te.getSchematicName()).toString();
    }
    final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), structureName, new PlacementSettings(), true);
    final Blueprint blueprint = structure.getBluePrint();
    blueprint.rotateWithMirror(BlockPosUtil.getRotationFromRotations(getRotation()), isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE, colony.getWorld());
    final BlockInfo info = blueprint.getBlockInfoAsMap().getOrDefault(blueprint.getPrimaryBlockOffset(), null);
    if (info.getTileEntityData() != null) {
        te.readSchematicDataFromNBT(info.getTileEntityData());
    }
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockInfo(com.ldtteam.structurize.util.BlockInfo) StructureName(com.ldtteam.structurize.management.StructureName) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 39 with StructureName

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

the class AbstractSchematicProvider method deserializerStructureInformationFrom.

private void deserializerStructureInformationFrom(final CompoundNBT compound) {
    final String md5 = compound.getString(TAG_SCHEMATIC_MD5);
    final int testLevel = buildingLevel == 0 ? 1 : buildingLevel;
    final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + testLevel);
    if (!Structures.hasMD5(sn)) {
        final StructureName newStructureName = Structures.getStructureNameByMD5(md5);
        if (newStructureName != null && newStructureName.getPrefix().equals(sn.getPrefix()) && newStructureName.getSchematic().equals(sn.getSchematic())) {
            // We found the new location for the schematic, update the style accordingly
            style = newStructureName.getStyle();
            Log.getLogger().warn(String.format("AbstractBuilding.readFromNBT: %s have been moved to %s", sn, newStructureName));
        }
    }
    if (style.isEmpty()) {
        Log.getLogger().warn("Loaded empty style, setting to wooden");
        style = "wooden";
    }
}
Also used : StructureName(com.ldtteam.structurize.management.StructureName) IAltersBuildingFootprint(com.minecolonies.api.colony.buildings.modules.IAltersBuildingFootprint) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 40 with StructureName

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

the class WorkManager method addWorkOrder.

/**
 * Adds work order to the work manager.
 *
 * @param order          Order to add.
 * @param readingFromNbt if being read from NBT.
 */
@Override
public void addWorkOrder(@NotNull final IWorkOrder order, final boolean readingFromNbt) {
    dirty = true;
    if (order instanceof WorkOrderBuildDecoration && !(order instanceof WorkOrderBuildMiner)) {
        for (final IWorkOrder or : workOrders.values()) {
            if (or instanceof WorkOrderBuildDecoration) {
                if (((WorkOrderBuildDecoration) or).getSchematicLocation().equals(((WorkOrderBuildDecoration) order).buildingLocation) && ((WorkOrderBuildDecoration) or).getStructureName().equals(((WorkOrderBuildDecoration) order).getStructureName())) {
                    Log.getLogger().warn("Avoiding adding duplicate workOrder");
                    removeWorkOrder(or);
                    break;
                }
            }
        }
        if (!readingFromNbt && !isWorkOrderWithinColony((WorkOrderBuildDecoration) order)) {
            LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), OUT_OF_COLONY, ((WorkOrderBuildDecoration) order).getName(), ((WorkOrderBuildDecoration) order).getSchematicLocation().getX(), ((WorkOrderBuildDecoration) order).getSchematicLocation().getZ());
            return;
        }
    }
    if (order.getID() == 0) {
        topWorkOrderId++;
        order.setID(topWorkOrderId);
    }
    if (order instanceof WorkOrderBuildDecoration && !readingFromNbt) {
        final StructureName structureName = new StructureName(((WorkOrderBuildDecoration) order).getStructureName());
        if (order instanceof WorkOrderBuildBuilding) {
            final int level = ((WorkOrderBuildBuilding) order).getUpgradeLevel();
            AdvancementUtils.TriggerAdvancementPlayersForColony(colony, player -> AdvancementTriggers.CREATE_BUILD_REQUEST.trigger(player, structureName, level));
        } else {
            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) StructureName(com.ldtteam.structurize.management.StructureName)

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