Search in sources :

Example 1 with ChangeStorage

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

the class Manager method redo.

/**
 * Undo a change to the world made by a player.
 *
 * @param player      the player who made it.
 * @param operationID
 */
public static void redo(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.redo.notfound"), player.getUUID());
        return;
    }
    for (final ChangeStorage storage : list) {
        if (storage.getID() == operationID) {
            if (!storage.isDone()) {
                player.sendMessage(new TranslationTextComponent("structurize.gui.undoredo.redo.inprogress", storage.getOperation()), player.getUUID());
                return;
            }
            player.sendMessage(new TranslationTextComponent("structurize.gui.undoredo.redo.add", storage.getOperation()), player.getUUID());
            addToQueue(new TickedWorldOperation(storage, player, TickedWorldOperation.OperationType.REDO));
            return;
        }
    }
    player.sendMessage(new TranslationTextComponent("structurize.gui.undoredo.redo.notfound"), player.getUUID());
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation) ChangeStorage(com.ldtteam.structurize.util.ChangeStorage)

Example 2 with ChangeStorage

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

the class RemoveEntityMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    if (!ctxIn.getSender().isCreative()) {
        return;
    }
    final World world = ctxIn.getSender().getLevel();
    final ChangeStorage storage = new ChangeStorage(TickedWorldOperation.OperationType.REMOVE_ENTITY.toString(), ctxIn.getSender().getUUID());
    for (int x = Math.min(from.getX(), to.getX()); x <= Math.max(from.getX(), to.getX()); x++) {
        for (int y = Math.min(from.getY(), to.getY()); y <= Math.max(from.getY(), to.getY()); y++) {
            for (int z = Math.min(from.getZ(), to.getZ()); z <= Math.max(from.getZ(), to.getZ()); z++) {
                final BlockPos here = new BlockPos(x, y, z);
                final List<Entity> list = world.getEntitiesOfClass(Entity.class, new AxisAlignedBB(here));
                storage.addEntities(list);
                for (final Entity entity : list) {
                    if (entity.getName().getString().equals(entityName)) {
                        entity.remove();
                    }
                }
            }
        }
    }
    Manager.addToUndoRedoCache(storage);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ChangeStorage(com.ldtteam.structurize.util.ChangeStorage)

Example 3 with ChangeStorage

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

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

the class OperationHistoryMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    if (isLogicalServer) {
        if (ctxIn.getSender() == null) {
            return;
        }
        final List<ChangeStorage> operations = Manager.getChangeStoragesForPlayer(ctxIn.getSender().getUUID());
        operationIDs = new ArrayList<>();
        for (final ChangeStorage storage : operations) {
            operationIDs.add(new Tuple<>(storage.getOperation(), storage.getID()));
        }
        Network.getNetwork().sendToPlayer(this, ctxIn.getSender());
    } else {
        WindowUndoRedo.lastOperations = operationIDs;
    }
}
Also used : ChangeStorage(com.ldtteam.structurize.util.ChangeStorage)

Aggregations

ChangeStorage (com.ldtteam.structurize.util.ChangeStorage)4 TickedWorldOperation (com.ldtteam.structurize.util.TickedWorldOperation)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 Entity (net.minecraft.entity.Entity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1