use of com.minecolonies.api.util.LoadOnlyStructureHandler in project minecolonies by Minecolonies.
the class WindowBuildDecoration method updateResources.
/**
* Clears and resets/updates all resources.
*/
private void updateResources() {
final World world = Minecraft.getInstance().level;
resources.clear();
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, structurePos, structureName.toString(), new PlacementSettings(), true);
final String md5 = Structures.getMD5(structureName.toString());
if (!structure.hasBluePrint() || !structure.isCorrectMD5(md5)) {
if (!structure.hasBluePrint()) {
Log.getLogger().info("Template structure " + structureName + " missing");
} else {
Log.getLogger().info("structure " + structureName + " md5 error");
}
Log.getLogger().info("Request To Server for structure " + structureName);
if (ServerLifecycleHooks.getCurrentServer() == null) {
com.ldtteam.structurize.Network.getNetwork().sendToServer(new SchematicRequestMessage(structureName.toString()));
return;
} else {
Log.getLogger().error("WindowMinecoloniesBuildTool: Need to download schematic on a standalone client/server. This should never happen", new Exception());
}
}
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(), true);
progressPos = result.getIteratorPos();
for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
addNeededResource(stack, stack.getCount());
}
} while (result.getBlockResult().getResult() != BlockPlacementResult.Result.FINISHED);
window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
updateResourceList();
}
use of com.minecolonies.api.util.LoadOnlyStructureHandler in project minecolonies by Minecolonies.
the class ClientEventHandler method handleRenderBuildTool.
/**
* Renders building bounding boxes into the client
*
* @param event The caught event
* @param world The world in which to render
* @param player The player for which to render
*/
private static void handleRenderBuildTool(@NotNull final RenderWorldLastEvent event, final ClientWorld world, final PlayerEntity player) {
if (Settings.instance.getActiveStructure() == null) {
return;
}
final IColonyView colony = IColonyManager.getInstance().getClosestColonyView(world, new BlockPos(player.position()));
if (colony == null) {
return;
}
final BlockPos activePosition = Settings.instance.getPosition();
final Map<BlockPos, Triple<Blueprint, BlockPos, BlockPos>> newCache = new HashMap<>();
for (final IBuildingView buildingView : colony.getBuildings()) {
if (MinecoloniesAPIProxy.getInstance().getConfig().getClient().neighborbuildingrendering.get()) {
if (buildingView.getBuildingType() == ModBuildings.postBox || buildingView.getBuildingType() == ModBuildings.stash) {
continue;
}
final BlockPos currentPosition = buildingView.getPosition();
if (activePosition.closerThan(currentPosition, PREVIEW_RANGE)) {
if (blueprintCache.containsKey(currentPosition)) {
newCache.put(currentPosition, blueprintCache.get(currentPosition));
continue;
}
final TileEntity tile = world.getBlockEntity(buildingView.getID());
String schematicName = buildingView.getSchematicName();
if (tile instanceof IBlueprintDataProvider) {
if (!((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
schematicName = ((IBlueprintDataProvider) tile).getSchematicName().replaceAll("\\d$", "");
}
}
final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, buildingView.getStyle(), schematicName + buildingView.getBuildingMaxLevel());
final String structureName = sn.toString();
final String md5 = Structures.getMD5(structureName);
final IStructureHandler wrapper = new LoadOnlyStructureHandler(world, buildingView.getID(), structureName, new PlacementSettings(), true);
if (!wrapper.hasBluePrint() || !wrapper.isCorrectMD5(md5)) {
if (alreadyRequestedStructures.contains(structureName)) {
continue;
}
alreadyRequestedStructures.add(structureName);
Log.getLogger().error("Couldn't find schematic: " + structureName + " requesting to server if possible.");
if (ServerLifecycleHooks.getCurrentServer() == null) {
Network.getNetwork().sendToServer(new SchematicRequestMessage(structureName));
}
continue;
}
final Blueprint blueprint = wrapper.getBluePrint();
final Mirror mirror = buildingView.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE;
blueprint.rotateWithMirror(BlockPosUtil.getRotationFromRotations(buildingView.getRotation()), mirror, world);
final BlockPos primaryOffset = blueprint.getPrimaryBlockOffset();
final BlockPos boxStartPos = currentPosition.subtract(primaryOffset);
final BlockPos size = new BlockPos(blueprint.getSizeX(), blueprint.getSizeY(), blueprint.getSizeZ());
final BlockPos boxEndPos = boxStartPos.offset(size).subtract(new BlockPos(1, 1, 1));
blueprint.setRenderSource(buildingView.getID());
if (buildingView.getBuildingLevel() < buildingView.getBuildingMaxLevel()) {
newCache.put(currentPosition, new Triple(blueprint, boxStartPos, boxEndPos));
} else {
newCache.put(currentPosition, new Triple<>(null, boxStartPos, boxEndPos));
}
}
}
}
blueprintCache = newCache;
for (final Map.Entry<BlockPos, Triple<Blueprint, BlockPos, BlockPos>> nearbyBuilding : blueprintCache.entrySet()) {
final Triple<Blueprint, BlockPos, BlockPos> buildingData = nearbyBuilding.getValue();
final BlockPos position = nearbyBuilding.getKey();
if (buildingData.a != null) {
StructureClientHandler.renderStructureAtPos(buildingData.a, event.getPartialTicks(), position, event.getMatrixStack());
}
RenderUtils.renderBox(buildingData.b, buildingData.c, 0, 0, 1, 1.0F, 0.002D, event.getMatrixStack(), linesWithCullAndDepth.get());
}
}
use of com.minecolonies.api.util.LoadOnlyStructureHandler 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.minecolonies.api.util.LoadOnlyStructureHandler 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.minecolonies.api.util.LoadOnlyStructureHandler 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;
}
Aggregations