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 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.minecolonies.api.util.LoadOnlyStructureHandler 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());
}
}
use of com.minecolonies.api.util.LoadOnlyStructureHandler 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.minecolonies.api.util.LoadOnlyStructureHandler in project minecolonies by Minecolonies.
the class DecorationBuildRequestMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
if (colony == null) {
return;
}
final PlayerEntity player = ctxIn.getSender();
// Verify player has permission to change this hut its settings
if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
return;
}
final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
if (entity instanceof TileEntityDecorationController) {
final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderDecoration).filter(entry -> entry.getValue().getLocation().equals(pos)).findFirst();
if (wo.isPresent()) {
colony.getWorkManager().removeWorkOrder(wo.get().getKey());
return;
}
int difference = 0;
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, 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 BlockDecorationController)) {
Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
return;
}
final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
if (structureRotation <= worldRotation) {
difference = worldRotation - structureRotation;
} else {
difference = 4 + worldRotation - structureRotation;
}
}
}
final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
final int currentLevel = ((TileEntityDecorationController) entity).getTier();
WorkOrderDecoration order;
if (level > currentLevel) {
order = WorkOrderDecoration.create(WorkOrderType.UPGRADE, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
} else if (level == currentLevel) {
order = WorkOrderDecoration.create(WorkOrderType.REPAIR, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
} else {
order = WorkOrderDecoration.create(WorkOrderType.BUILD, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
}
colony.getWorkManager().addWorkOrder(order, false);
}
}
use of com.minecolonies.api.util.LoadOnlyStructureHandler in project minecolonies by ldtteam.
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();
}
Aggregations