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