Search in sources :

Example 6 with TickedWorldOperation

use of com.ldtteam.structurize.util.TickedWorldOperation 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 7 with TickedWorldOperation

use of com.ldtteam.structurize.util.TickedWorldOperation in project Structurize by ldtteam.

the class Manager method undo.

/**
 * Undo a change to the world made by a player.
 *
 * @param player      the player who made it.
 * @param operationID
 */
public static void undo(final PlayerEntity player, final int operationID) {
    final List<ChangeStorage> list = changeQueue.get(player.getUUID());
    if (list == null || list.isEmpty()) {
        player.sendMessage(new TranslationTextComponent("structurize.gui.undoredo.undo.notfound"), player.getUUID());
        return;
    }
    for (final Iterator<ChangeStorage> iterator = list.iterator(); iterator.hasNext(); ) {
        final ChangeStorage storage = iterator.next();
        if (storage.getID() == operationID) {
            if (!storage.isDone()) {
                player.sendMessage(new TranslationTextComponent("structurize.gui.undoredo.undo.inprogress", storage.getOperation()), player.getUUID());
                return;
            }
            player.sendMessage(new TranslationTextComponent("structurize.gui.undoredo.undo.add", storage.getOperation()), player.getUUID());
            addToQueue(new TickedWorldOperation(storage, player, TickedWorldOperation.OperationType.UNDO));
            if (storage.getOperation().indexOf(TickedWorldOperation.OperationType.UNDO.toString()) == 0) {
                iterator.remove();
            }
            return;
        }
    }
    player.sendMessage(new TranslationTextComponent("structurize.gui.undoredo.undo.notfound"), player.getUUID());
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation) ChangeStorage(com.ldtteam.structurize.util.ChangeStorage)

Example 8 with TickedWorldOperation

use of com.ldtteam.structurize.util.TickedWorldOperation 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

TickedWorldOperation (com.ldtteam.structurize.util.TickedWorldOperation)8 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)6 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)6 NotNull (org.jetbrains.annotations.NotNull)6 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)4 CreativeStructureHandler (com.ldtteam.structurize.placement.structure.CreativeStructureHandler)2 ChangeStorage (com.ldtteam.structurize.util.ChangeStorage)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2