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 IWorkOrder order) {
final World world = colony.getWorld();
final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(order.getLocation(), world, new LoadOnlyStructureHandler(world, order.getLocation(), order.getStructureName(), new PlacementSettings(), true).getBluePrint(), order.getRotation(), 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 CreativeRaiderStructureHandler 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 colonyId the colony id.
* @param event the raid event.
* @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, final int colonyId, final IColonyRaidEvent event, @Nullable final ServerPlayerEntity player) {
try {
@NotNull final IStructureHandler structure = new CreativeRaiderStructureHandler(worldObj, pos, name, new PlacementSettings(mirror, rotation), fancyPlacement, event, colonyId);
if (structure.hasBluePrint()) {
@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 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 IWorkOrder workOrder, @NotNull final World world) {
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, workOrder.getLocation(), workOrder.getStructureName(), new PlacementSettings(), true);
if (structure.hasBluePrint()) {
final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(workOrder.getLocation(), world, structure.getBluePrint(), workOrder.getRotation(), workOrder.isMirrored());
removeConstructionTape(corners, world);
}
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
the class AbstractBuilding method calculateCorners.
@Override
public void calculateCorners() {
final AbstractTileEntityColonyBuilding te = getTileEntity();
if (te != null && !te.getSchematicName().isEmpty()) {
setCorners(te.getInWorldCorners().getA(), te.getInWorldCorners().getB());
return;
}
final WorkOrderBuilding workOrder = WorkOrderBuilding.create(WorkOrderType.BUILD, this);
final LoadOnlyStructureHandler wrapper = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), workOrder.getStructureName(), new PlacementSettings(), true);
if (!wrapper.hasBluePrint()) {
setCorners(getPosition(), getPosition());
return;
}
final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(this.getPosition(), colony.getWorld(), wrapper.getBluePrint(), workOrder.getRotation(), workOrder.isMirrored());
this.setCorners(corners.getA(), corners.getB());
}
use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.
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;
}
Aggregations