use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.
the class BuildingCook method initTagPositions.
/**
* Reads the tag positions
*/
public void initTagPositions() {
if (initTags) {
return;
}
final IBlueprintDataProvider te = getTileEntity();
if (te != null) {
initTags = true;
sitPositions = new ArrayList<>();
for (final Map.Entry<BlockPos, List<String>> entry : te.getWorldTagPosMap().entrySet()) {
if (entry.getValue().contains(TAG_SITTING)) {
sitPositions.add(entry.getKey());
}
}
}
}
use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.
the class AbstractEntityAIStructureWithWorkOrder method executeSpecificCompleteActions.
@Override
public void executeSpecificCompleteActions() {
if (job.getBlueprint() == null && job.hasWorkOrder()) {
// fix for bad structures
job.complete();
}
if (job.getBlueprint() == null) {
return;
}
final String structureName = job.getBlueprint().getName();
final WorkOrderBuildDecoration wo = job.getWorkOrder();
if (wo instanceof WorkOrderBuildBuilding) {
sendCompletionMessage(wo);
WorkOrderBuild wob = (WorkOrderBuild) wo;
String buildingName = wo.getStructureName();
buildingName = buildingName.substring(buildingName.indexOf('/') + 1, buildingName.lastIndexOf('/')) + " " + buildingName.substring(buildingName.lastIndexOf('/') + 1, buildingName.lastIndexOf(String.valueOf(wob.getUpgradeLevel())));
job.getColony().getEventDescriptionManager().addEventDescription(wob.getUpgradeLevel() > 1 ? new BuildingUpgradedEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()) : new BuildingBuiltEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()));
} else if (wo instanceof WorkOrderBuildRemoval) {
worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_DECONSTRUCTION_COMPLETE, structureName);
WorkOrderBuild wob = (WorkOrderBuild) wo;
String buildingName = wo.getStructureName();
buildingName = buildingName.substring(buildingName.indexOf('/') + 1, buildingName.lastIndexOf('/')) + " " + buildingName.substring(buildingName.lastIndexOf('/') + 1, buildingName.indexOf(String.valueOf(wob.getUpgradeLevel())));
job.getColony().getEventDescriptionManager().addEventDescription(new BuildingDeconstructedEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()));
} else {
sendCompletionMessage(wo);
}
if (wo == null) {
Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
} else {
job.complete();
if (wo instanceof WorkOrderBuildBuilding) {
final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()));
} else {
// Normally levels are done through the schematic data, but incase it is missing we do it manually here.
final TileEntity te = worker.level.getBlockEntity(building.getID());
if (te instanceof AbstractTileEntityColonyBuilding && ((IBlueprintDataProvider) te).getSchematicName().isEmpty()) {
building.onUpgradeComplete(((WorkOrderBuildBuilding) wo).getUpgradeLevel());
building.setBuildingLevel(((WorkOrderBuildBuilding) wo).getUpgradeLevel());
}
}
} else if (wo instanceof WorkOrderBuildRemoval) {
final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()));
} else {
building.setDeconstructed();
}
}
}
getOwnBuilding().resetNeededResources();
}
use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.
the class WindowBuildBuilding method updateResources.
/**
* Clears and resets/updates all resources.
*/
private void updateResources() {
if (stylesDropDownList.getSelectedIndex() == -1) {
return;
}
final World world = Minecraft.getInstance().level;
resources.clear();
final IBuildingView parentBuilding = building.getColony().getBuilding(building.getParent());
int nextLevel = building.getBuildingLevel();
if (building.getBuildingLevel() < building.getBuildingMaxLevel() && (parentBuilding == null || building.getBuildingLevel() < parentBuilding.getBuildingLevel())) {
nextLevel = building.getBuildingLevel() + 1;
}
final TileEntity tile = world.getBlockEntity(building.getID());
String schematicName = building.getSchematicName();
if (tile instanceof IBlueprintDataProvider) {
if (!((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
schematicName = ((IBlueprintDataProvider) tile).getSchematicName().replaceAll("\\d$", "");
}
}
final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, styles.get(stylesDropDownList.getSelectedIndex()), schematicName + nextLevel);
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, building.getPosition(), sn.toString(), new PlacementSettings(), true);
final String md5 = Structures.getMD5(sn.toString());
if (!structure.hasBluePrint() || !structure.isCorrectMD5(md5)) {
if (!structure.hasBluePrint()) {
Log.getLogger().info("Template structure " + sn + " missing");
} else {
Log.getLogger().info("structure " + sn + " md5 error");
}
Log.getLogger().info("Request To Server for structure " + sn);
if (ServerLifecycleHooks.getCurrentServer() == null) {
com.ldtteam.structurize.Network.getNetwork().sendToServer(new SchematicRequestMessage(sn.toString()));
return;
} else {
Log.getLogger().error("WindowMinecoloniesBuildTool: Need to download schematic on a standalone client/server. This should never happen", new Exception());
}
}
if (!structure.hasBluePrint()) {
findPaneOfTypeByID(BUTTON_BUILD, Button.class).hide();
findPaneOfTypeByID(BUTTON_REPAIR, Button.class).hide();
findPaneOfTypeByID(BUTTON_PICKUP_BUILDING, Button.class).show();
return;
}
structure.getBluePrint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(building.getRotation()), building.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE, world);
StructurePlacer placer = new StructurePlacer(structure);
StructurePhasePlacementResult result;
BlockPos progressPos = NULL_POS;
do {
result = placer.executeStructureStep(world, null, progressPos, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.and((info, pos, handler) -> false)), true);
progressPos = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
addNeededResource(stack, stack.getCount());
}
} while (result != null && result.getBlockResult().getResult() != BlockPlacementResult.Result.FINISHED);
window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
updateResourceList();
}
use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project minecolonies by ldtteam.
the class AbstractJobStructure method complete.
/**
* Do final completion when the Job's current work is complete.
*/
public void complete() {
getWorkOrder().onCompleted(getCitizen().getColony(), this.getCitizen());
if (blueprint != null) {
final CompoundNBT[][][] tileEntityData = blueprint.getTileEntities();
for (short x = 0; x < blueprint.getSizeX(); x++) {
for (short y = 0; y < blueprint.getSizeY(); y++) {
for (short z = 0; z < blueprint.getSizeZ(); z++) {
final CompoundNBT compoundNBT = tileEntityData[y][z][x];
if (compoundNBT != null && compoundNBT.contains(TAG_BLUEPRINTDATA)) {
final BlockPos tePos = getWorkOrder().getSchematicLocation().subtract(blueprint.getPrimaryBlockOffset()).offset(x, y, z);
final TileEntity te = getColony().getWorld().getBlockEntity(tePos);
if (te instanceof IBlueprintDataProvider) {
((IBlueprintDataProvider) te).readSchematicDataFromNBT(compoundNBT);
((ServerWorld) getColony().getWorld()).getChunkSource().blockChanged(tePos);
te.setChanged();
}
}
}
}
}
}
getCitizen().getColony().getWorkManager().removeWorkOrder(workOrderId);
setWorkOrder(null);
setBlueprint(null);
}
use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider in project Structurize by ldtteam.
the class WindowTagTool method removeTag.
/**
* Removes a block pos
*
* @param button
*/
private void removeTag(final Button button) {
int row = tagList.getListElementIndexByPane(button);
BlockPos toRemove = positionsList.get(row);
TileEntity te = world.getBlockEntity(anchorPos);
if (te instanceof IBlueprintDataProvider) {
IBlueprintDataProvider dataTE = (IBlueprintDataProvider) te;
Map<BlockPos, List<String>> map = dataTE.getPositionedTags();
if (map.containsKey(toRemove) && !map.get(toRemove).isEmpty()) {
String tag = map.get(toRemove).get(map.get(toRemove).size() - 1);
dataTE.removeTag(toRemove, tag);
Network.getNetwork().sendToServer(new AddRemoveTagMessage(false, tag, toRemove, anchorPos));
}
updateResourceList();
} else {
close();
}
}
Aggregations