use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class AbstractEntityAIStructure method loadStructure.
/**
* Loads the structure given the name, rotation and position.
*
* @param name the name to retrieve it.
* @param rotateTimes number of times to rotateWithMirror it.
* @param position the position to set it.
* @param isMirrored is the structure mirroed?
* @param removal if removal step.
*/
public void loadStructure(@NotNull final String name, final int rotateTimes, final BlockPos position, final boolean isMirrored, final boolean removal) {
final BuildingStructureHandler<J, B> structure;
IBuilding colonyBuilding = worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(position);
final TileEntity entity = world.getBlockEntity(position);
if (removal) {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { REMOVE_WATER, REMOVE });
building.setTotalStages(2);
} else if ((colonyBuilding != null && (colonyBuilding.getBuildingLevel() > 0 || colonyBuilding.hasParent())) || (entity instanceof TileEntityDecorationController && ((TileEntityDecorationController) entity).getTier() > 0)) {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { BUILD_SOLID, CLEAR_WATER, CLEAR_NON_SOLIDS, DECORATE, SPAWN });
building.setTotalStages(5);
} else {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { CLEAR, BUILD_SOLID, CLEAR_WATER, CLEAR_NON_SOLIDS, DECORATE, SPAWN });
building.setTotalStages(6);
}
if (!structure.hasBluePrint()) {
handleSpecificCancelActions();
Log.getLogger().warn("Couldn't find structure with name: " + name + " aborting loading procedure");
return;
}
job.setBlueprint(structure.getBluePrint());
job.getBlueprint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(rotateTimes), isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, world);
setStructurePlacer(structure);
if (getProgressPos() != null) {
structure.setStage(getProgressPos().getB());
}
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class AbstractEntityAIStructureWithWorkOrder method requestMaterials.
@Override
public boolean requestMaterials() {
StructurePhasePlacementResult result;
final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
if (job.getWorkOrder().getIteratorType().isEmpty()) {
final String mode = BuilderModeSetting.getActualValue(building);
job.getWorkOrder().setIteratorType(mode);
}
final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
if (requestProgress == null) {
final AbstractBuildingStructureBuilder buildingWorker = building;
buildingWorker.resetNeededResources();
requestProgress = NULL_POS;
requestState = RequestStage.SOLID;
}
final RequestStage currState = requestState;
switch(currState) {
case SOLID:
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()))), false);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
building.addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.DECO;
}
return false;
case DECO:
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()))), false);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
building.addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.ENTITIES;
}
return false;
case ENTITIES:
result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0)), true);
requestProgress = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
building.addNeededResource(stack, stack.getCount());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
requestState = RequestStage.SOLID;
requestProgress = null;
return true;
}
return false;
default:
return true;
}
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class ConstructionTapeHelper method placeConstructionTape.
/**
* Calculates the borders for the workOrderBuildDecoration and sends it to the placement.
*
* @param workOrder the workOrder.
* @param world the world.
*/
public static void placeConstructionTape(@NotNull final WorkOrderDecoration workOrder, @NotNull final World world) {
final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(workOrder.getLocation(), world, new LoadOnlyStructureHandler(world, workOrder.getLocation(), workOrder.getStructureName(), new PlacementSettings(), true).getBluePrint(), workOrder.getRotation(), workOrder.isMirrored());
placeConstructionTape(corners, world);
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class CreativeBuildingStructureHandler method loadAndPlaceStructureWithRotation.
/**
* Load a structure into this world and place it in the right position and rotation.
*
* @param worldObj the world to load it in
* @param name the structures name
* @param pos coordinates
* @param rotation the rotation.
* @param mirror the mirror used.
* @param fancyPlacement if fancy or complete.
* @param player the placing player.
* @return the placed blueprint.
*/
public static Blueprint loadAndPlaceStructureWithRotation(final World worldObj, @NotNull final String name, @NotNull final BlockPos pos, final Rotation rotation, @NotNull final Mirror mirror, final boolean fancyPlacement, @Nullable final ServerPlayerEntity player) {
try {
@NotNull final IStructureHandler structure = new CreativeBuildingStructureHandler(worldObj, pos, name, new PlacementSettings(mirror, rotation), fancyPlacement);
if (structure.hasBluePrint()) {
structure.getBluePrint().rotateWithMirror(rotation, mirror, worldObj);
@NotNull final StructurePlacer instantPlacer = new StructurePlacer(structure);
Manager.addToQueue(new TickedWorldOperation(instantPlacer, player));
}
return structure.getBluePrint();
} catch (final IllegalStateException e) {
Log.getLogger().warn("Could not load structure!", e);
}
return null;
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class ShipBasedRaiderUtils method canSpawnShipAt.
/**
* Checks whether a pirate event is possible at this place.
*
* @param colony the colony.
* @param spawnPoint the spawn point.
* @param raidLevel the raid level.
* @param rotation the rotation.
* @return true if successful.
*/
public static boolean canSpawnShipAt(final IColony colony, final BlockPos spawnPoint, final int raidLevel, final int rotation, final String shipName) {
if (spawnPoint.equals(colony.getCenter()) || spawnPoint.getY() > MineColonies.getConfig().getServer().maxYForBarbarians.get()) {
return false;
}
final World world = colony.getWorld();
final String shipSize = ShipSize.getShipForRaiderAmount(raidLevel).schematicPrefix + shipName;
final CreativeBuildingStructureHandler structure = new CreativeBuildingStructureHandler(colony.getWorld(), spawnPoint, Structures.SCHEMATICS_PREFIX + SHIP_FOLDER + shipSize, new PlacementSettings(), true);
structure.getBluePrint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(rotation), Mirror.NONE, colony.getWorld());
return canPlaceShipAt(spawnPoint, structure.getBluePrint(), world) || canPlaceShipAt(spawnPoint.below(), structure.getBluePrint(), world);
}
Aggregations