Search in sources :

Example 6 with IStructureHandler

use of com.ldtteam.structurize.placement.structure.IStructureHandler 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;
}
Also used : IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull) TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation)

Example 7 with IStructureHandler

use of com.ldtteam.structurize.placement.structure.IStructureHandler in project Structurize by ldtteam.

the class StructurePlacementUtils method unloadStructure.

/**
 * Unload a structure at a certain location.
 *
 * @param world    the world.
 * @param startPos      the position.
 * @param name    the name.
 * @param rotation the rotation.
 * @param mirror   the mirror.
 */
public static void unloadStructure(@NotNull final World world, @NotNull final BlockPos startPos, @NotNull final String name, final Rotation rotation, @NotNull final Mirror mirror) {
    @NotNull final IStructureHandler structure = new CreativeStructureHandler(world, startPos, name, new PlacementSettings(mirror, rotation), false);
    structure.getBluePrint().rotateWithMirror(rotation, mirror, world);
    @NotNull final StructurePlacer placer = new StructurePlacer(structure);
    placer.executeStructureStep(world, null, new BlockPos(0, 0, 0), StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().increment((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock), true);
}
Also used : TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation) World(net.minecraft.world.World) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos) Mirror(net.minecraft.util.Mirror) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) Manager(com.ldtteam.structurize.management.Manager) CreativeStructureHandler(com.ldtteam.structurize.placement.structure.CreativeStructureHandler) Rotation(net.minecraft.util.Rotation) Log(com.ldtteam.structurize.api.util.Log) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CreativeStructureHandler(com.ldtteam.structurize.placement.structure.CreativeStructureHandler) AirBlock(net.minecraft.block.AirBlock) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with IStructureHandler

use of com.ldtteam.structurize.placement.structure.IStructureHandler in project Structurize by ldtteam.

the class StructurePlacementUtils 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 blueprint the structures blueprint
 * @param pos      coordinates
 * @param rotation the rotation.
 * @param mirror   the mirror used.
 * @param fancyPlacement if fancy or complete.
 * @param player   the placing player.
 */
public static void loadAndPlaceStructureWithRotation(final World worldObj, @NotNull final Blueprint blueprint, @NotNull final BlockPos pos, final Rotation rotation, @NotNull final Mirror mirror, final boolean fancyPlacement, final ServerPlayerEntity player) {
    try {
        @NotNull final IStructureHandler structure = new CreativeStructureHandler(worldObj, pos, blueprint, new PlacementSettings(mirror, rotation), fancyPlacement);
        if (fancyPlacement) {
            structure.fancyPlacement();
        }
        structure.getBluePrint().rotateWithMirror(rotation, mirror, worldObj);
        @NotNull final StructurePlacer instantPlacer = new StructurePlacer(structure);
        Manager.addToQueue(new TickedWorldOperation(instantPlacer, player));
    } catch (final IllegalStateException e) {
        Log.getLogger().warn("Could not load structure!", e);
    }
}
Also used : CreativeStructureHandler(com.ldtteam.structurize.placement.structure.CreativeStructureHandler) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull) TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation)

Example 9 with IStructureHandler

use of com.ldtteam.structurize.placement.structure.IStructureHandler in project minecolonies by ldtteam.

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());
    }
}
Also used : IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) StructureName(com.ldtteam.structurize.management.StructureName) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Triple(org.antlr.v4.runtime.misc.Triple) TileEntity(net.minecraft.tileentity.TileEntity) SchematicRequestMessage(com.ldtteam.structurize.network.messages.SchematicRequestMessage) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) IColonyView(com.minecolonies.api.colony.IColonyView) Mirror(net.minecraft.util.Mirror) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 10 with IStructureHandler

use of com.ldtteam.structurize.placement.structure.IStructureHandler in project minecolonies by ldtteam.

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;
}
Also used : IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull) TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation)

Aggregations

IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)10 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)10 TickedWorldOperation (com.ldtteam.structurize.util.TickedWorldOperation)7 NotNull (org.jetbrains.annotations.NotNull)7 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)4 CreativeStructureHandler (com.ldtteam.structurize.placement.structure.CreativeStructureHandler)4 BlockPos (net.minecraft.util.math.BlockPos)4 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)3 StructureName (com.ldtteam.structurize.management.StructureName)3 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)3 Mirror (net.minecraft.util.Mirror)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)2 IColonyView (com.minecolonies.api.colony.IColonyView)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Triple (org.antlr.v4.runtime.misc.Triple)2 Log (com.ldtteam.structurize.api.util.Log)1 Manager (com.ldtteam.structurize.management.Manager)1