use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
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.util.PlacementSettings in project minecolonies by Minecolonies.
the class EntityAIQuarrier method requestMaterials.
@Override
public boolean requestMaterials() {
StructurePhasePlacementResult result;
final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
job.getWorkOrder().setIteratorType("default");
final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
if (requestProgress == null) {
final AbstractBuildingStructureBuilder buildingWorker = building;
buildingWorker.resetNeededResources();
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), structurePlacer.getB().getBluePrint().getSizeY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
requestState = RequestStage.SOLID;
}
final BlockPos worldPos = structure.getProgressPosInWorld(requestProgress);
final RequestStage currState = requestState;
switch(currState) {
case SOLID:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() < worldPos.getY())), false);
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
building.addNeededResource(stack, stack.getCount());
}
if (requestProgress.getY() != -1 && result.getIteratorPos().getY() < requestProgress.getY()) {
requestProgress = new BlockPos(0, requestProgress.getY() + 1, 0);
requestState = RequestStage.DECO;
} else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestProgress = new BlockPos(0, structurePlacer.getB().getBluePrint().getSizeY() - 2, 0);
requestState = RequestStage.DECO;
} else {
requestProgress = result.getIteratorPos();
}
return false;
case DECO:
if (requestProgress.getY() >= structurePlacer.getB().getBluePrint().getSizeY()) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
return false;
}
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() > worldPos.getY())), false);
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
building.addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else if (requestProgress.getY() != -1 && result.getIteratorPos().getY() > requestProgress.getY()) {
requestState = RequestStage.ENTITIES;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else {
requestProgress = result.getIteratorPos();
}
return false;
case ENTITIES:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0 || pos.getY() < worldPos.getY())), true);
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.SOLID;
requestProgress = null;
return true;
} else if (requestProgress.getY() != -1 && (result.getIteratorPos().getY() < requestProgress.getY())) {
requestState = RequestStage.SOLID;
requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
} else {
requestProgress = result.getIteratorPos();
}
return false;
}
return true;
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class WorkManager method isWorkOrderWithinColony.
/**
* Check if the workOrder is within a colony.
*
* @param order the workorder to check.
* @return true if so.
*/
private boolean isWorkOrderWithinColony(final WorkOrderBuildDecoration order) {
final World world = colony.getWorld();
final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(order.getSchematicLocation(), world, new LoadOnlyStructureHandler(world, order.getSchematicLocation(), order.getStructureName(), new PlacementSettings(), true).getBluePrint(), order.getRotation(world), order.isMirrored());
Set<ChunkPos> chunks = new HashSet<>();
final int minX = Math.min(corners.getA().getX(), corners.getB().getX()) + 1;
final int maxX = Math.max(corners.getA().getX(), corners.getB().getX());
final int minZ = Math.min(corners.getA().getZ(), corners.getB().getZ()) + 1;
final int maxZ = Math.max(corners.getA().getZ(), corners.getB().getZ());
for (int x = minX; x < maxX; x += 16) {
for (int z = minZ; z < maxZ; z += 16) {
final int chunkX = x >> 4;
final int chunkZ = z >> 4;
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
if (!chunks.contains(pos)) {
chunks.add(pos);
final IColonyTagCapability colonyCap = world.getChunk(pos.x, pos.z).getCapability(CLOSE_COLONY_CAP, null).orElseGet(null);
if (colonyCap == null || colonyCap.getOwningColony() != colony.getID()) {
return false;
}
}
}
}
return true;
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class ConstructionTapeHelper method removeConstructionTape.
/**
* Calculates the borders for the workOrderBuildDecoration and sends it to the removal.
*
* @param workOrder the workOrder.
* @param world the world.
*/
public static void removeConstructionTape(@NotNull final WorkOrderBuildDecoration workOrder, @NotNull final World world) {
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, workOrder.getSchematicLocation(), workOrder.getStructureName(), new PlacementSettings(), true);
if (structure.hasBluePrint()) {
final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(workOrder.getSchematicLocation(), world, structure.getBluePrint(), workOrder.getRotation(world), workOrder.isMirrored());
removeConstructionTape(corners, world);
}
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class ClientEventHandler method handleRenderScepterGuard.
/**
* Renders the guard scepter objects into the world.
*
* @param event The caught event
* @param world The world in which to render
* @param player The player for which to render
*/
private static void handleRenderScepterGuard(@NotNull final RenderWorldLastEvent event, final ClientWorld world, final PlayerEntity player) {
final PlacementSettings settings = new PlacementSettings(Settings.instance.getMirror(), BlockPosUtil.getRotationFromRotations(Settings.instance.getRotation()));
final ItemStack stack = player.getMainHandItem();
if (!stack.hasTag()) {
return;
}
final CompoundNBT compound = stack.getTag();
final IColonyView colony = IColonyManager.getInstance().getColonyView(compound.getInt(TAG_ID), player.level.dimension());
if (colony == null) {
return;
}
final BlockPos guardTower = BlockPosUtil.read(compound, TAG_POS);
final IBuildingView hut = colony.getBuilding(guardTower);
if (hut == null) {
return;
}
if (partolPointTemplate == null) {
partolPointTemplate = new LoadOnlyStructureHandler(world, hut.getPosition(), "schematics/infrastructure/patrolpoint", settings, true).getBluePrint();
}
if (hut instanceof AbstractBuildingGuards.View) {
StructureClientHandler.renderStructureAtPosList(partolPointTemplate, event.getPartialTicks(), ((AbstractBuildingGuards.View) hut).getPatrolTargets().stream().map(BlockPos::above).collect(Collectors.toList()), event.getMatrixStack());
}
}
Aggregations