Search in sources :

Example 11 with LoadOnlyStructureHandler

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);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 12 with LoadOnlyStructureHandler

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());
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) IColonyView(com.minecolonies.api.colony.IColonyView) IColonyView(com.minecolonies.api.colony.IColonyView) EmptyView(com.minecolonies.coremod.colony.buildings.views.EmptyView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView)

Example 13 with LoadOnlyStructureHandler

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);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 14 with LoadOnlyStructureHandler

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);
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) WordUtils(org.apache.commons.lang3.text.WordUtils) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) Action(com.minecolonies.api.colony.permissions.Action) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) RegistryKey(net.minecraft.util.RegistryKey) WorkOrderDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderDecoration) WorkOrderType(com.minecolonies.api.colony.workorders.WorkOrderType) Map(java.util.Map) Log(com.minecolonies.api.util.Log) BlockState(net.minecraft.block.BlockState) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) LogicalSide(net.minecraftforge.fml.LogicalSide) IMessage(com.minecolonies.api.network.IMessage) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Registry(net.minecraft.util.registry.Registry) Nullable(org.jetbrains.annotations.Nullable) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) IColony(com.minecolonies.api.colony.IColony) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) WorkOrderDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderDecoration) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler)

Example 15 with LoadOnlyStructureHandler

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();
}
Also used : SchematicRequestMessage(com.ldtteam.structurize.network.messages.SchematicRequestMessage) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Aggregations

PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)21 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)21 BlockPos (net.minecraft.util.math.BlockPos)19 World (net.minecraft.world.World)9 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)6 StructureName (com.ldtteam.structurize.management.StructureName)6 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)6 IColonyView (com.minecolonies.api.colony.IColonyView)6 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)6 ItemStack (net.minecraft.item.ItemStack)6 TileEntity (net.minecraft.tileentity.TileEntity)6 BlockState (net.minecraft.block.BlockState)5 ScrollingList (com.ldtteam.blockout.views.ScrollingList)4 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)4 StructurePhasePlacementResult (com.ldtteam.structurize.placement.StructurePhasePlacementResult)4 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)4 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)4 Log (com.minecolonies.api.util.Log)4 Mirror (net.minecraft.util.Mirror)4 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)3