From a9919d130c6c64955fe2501a8e04af8c49703b0a Mon Sep 17 00:00:00 2001 From: IronApollo Date: Wed, 9 Jan 2019 03:32:38 -0500 Subject: [PATCH] Current progress #4 --- .../com/boydti/fawe/object/NullChangeSet.java | 12 +++ .../changeset/AbstractDelegateChangeSet.java | 12 +++ .../fawe/object/changeset/AnvilHistory.java | 12 +++ .../fawe/object/changeset/CFIChangeSet.java | 12 +++ .../changeset/CPUOptimizedChangeSet.java | 12 +++ .../object/changeset/DiskStorageHistory.java | 12 +++ .../changeset/MemoryOptimizedHistory.java | 12 +++ .../extent/reorder/MultiStageReorder.java | 62 ++++++++-------- .../function/operation/SetLocatedBlocks.java | 56 ++++++++++++++ .../history/changeset/ArrayListHistory.java | 73 +++++++++++++++++++ .../history/changeset/ChangeSet.java | 16 +++- .../internal/cui/ServerCUIHandler.java | 4 +- 12 files changed, 260 insertions(+), 35 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/SetLocatedBlocks.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java index 31bc342ad..7117c30f0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/NullChangeSet.java @@ -72,4 +72,16 @@ public class NullChangeSet extends FaweChangeSet { public final int size() { return 0; } + + @Override + public boolean isRecordingChanges() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setRecordChanges(boolean recordChanges) { + // TODO Auto-generated method stub + + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java index ab411e890..325391d5c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java @@ -172,4 +172,16 @@ public class AbstractDelegateChangeSet extends FaweChangeSet { public void add(int x, int y, int z, int combinedFrom, BaseBlock to) { parent.add(x, y, z, combinedFrom, to); } + + @Override + public boolean isRecordingChanges() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setRecordChanges(boolean recordChanges) { + // TODO Auto-generated method stub + + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AnvilHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AnvilHistory.java index 9391df381..59d05127f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AnvilHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AnvilHistory.java @@ -102,4 +102,16 @@ public class AnvilHistory extends FaweChangeSet implements IAnvilHistory { public int size() { return size == -1 ? folder.listFiles().length : size; } + + @Override + public boolean isRecordingChanges() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setRecordChanges(boolean recordChanges) { + // TODO Auto-generated method stub + + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CFIChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CFIChangeSet.java index de448e6ed..ad9deebc2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CFIChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CFIChangeSet.java @@ -78,4 +78,16 @@ public class CFIChangeSet extends FaweChangeSet { public int size() { return 1; } + + @Override + public boolean isRecordingChanges() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setRecordChanges(boolean recordChanges) { + // TODO Auto-generated method stub + + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CPUOptimizedChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CPUOptimizedChangeSet.java index f0b32d627..3b293c0ea 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CPUOptimizedChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/CPUOptimizedChangeSet.java @@ -107,4 +107,16 @@ public class CPUOptimizedChangeSet extends FaweChangeSet { public int size() { return changes.size() * 65536; // num chunks * 65536 (guess of 65536 changes per chunk) } + + @Override + public boolean isRecordingChanges() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setRecordChanges(boolean recordChanges) { + // TODO Auto-generated method stub + + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 9ad52aec6..455d03d6f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -509,4 +509,16 @@ public class DiskStorageHistory extends FaweStreamChangeSet { return count; } } + + @Override + public boolean isRecordingChanges() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setRecordChanges(boolean recordChanges) { + // TODO Auto-generated method stub + + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java index 2c530b064..f2f44f93a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java @@ -238,4 +238,16 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet { public NBTInputStream getTileRemoveIS() throws IOException { return tileR == null ? null : new NBTInputStream(MainUtil.getCompressedIS(new FastByteArraysInputStream(tileR))); } + + @Override + public boolean isRecordingChanges() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setRecordChanges(boolean recordChanges) { + // TODO Auto-generated method stub + + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index 145f5214a..c5c11d51c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -29,9 +29,10 @@ import com.sk89q.worldedit.function.operation.BlockMapEntryPlacer; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; import com.sk89q.worldedit.function.operation.RunContext; -import com.sk89q.worldedit.function.operation.SetLocatedBlocks; +//import com.sk89q.worldedit.function.operation.SetLocatedBlocks; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; +import com.sk89q.worldedit.util.LocatedBlock; import com.sk89q.worldedit.util.collection.TupleArrayList; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -51,9 +52,9 @@ import java.util.Set; */ public class MultiStageReorder extends AbstractDelegateExtent implements ReorderingExtent { - private TupleArrayList stage1 = new TupleArrayList<>(); - private TupleArrayList stage2 = new TupleArrayList<>(); - private TupleArrayList stage3 = new TupleArrayList<>(); + private TupleArrayList stage1 = new TupleArrayList<>(); + private TupleArrayList stage2 = new TupleArrayList<>(); + private TupleArrayList stage3 = new TupleArrayList<>(); private boolean enabled; /** @@ -95,13 +96,8 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder } @Override -<<<<<<< HEAD - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { - BlockStateHolder existing = getBlock(location); -======= public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { BlockState existing = getBlock(location); ->>>>>>> 399e0ad5... Refactor vector system to be cleaner if (!enabled) { return super.setBlock(location, block); @@ -109,30 +105,30 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder if (Blocks.shouldPlaceLast(block.getBlockType())) { // Place torches, etc. last -<<<<<<< HEAD - stage2.put(location.toBlockVector(), block); +//<<<<<<< HEAD + stage2.put(location, block); return !existing.equalsFuzzy(block); } else if (Blocks.shouldPlaceFinal(block.getBlockType())) { // Place signs, reed, etc even later - stage3.put(location.toBlockVector(), block); -======= - stage2.add(location, block); - return !existing.equalsFuzzy(block); - } else if (Blocks.shouldPlaceFinal(block.getBlockType())) { - // Place signs, reed, etc even later - stage3.add(location, block); ->>>>>>> 399e0ad5... Refactor vector system to be cleaner + stage3.put(location, block); +//======= +// stage2.add(location, block); +// return !existing.equalsFuzzy(block); +// } else if (Blocks.shouldPlaceFinal(block.getBlockType())) { +// // Place signs, reed, etc even later +// stage3.add(location, block); +//>>>>>>> 399e0ad5... Refactor vector system to be cleaner return !existing.equalsFuzzy(block); } else if (Blocks.shouldPlaceLast(existing.getBlockType())) { // Destroy torches, etc. first super.setBlock(location, BlockTypes.AIR.getDefaultState()); return super.setBlock(location, block); } else { -<<<<<<< HEAD - stage1.put(location.toBlockVector(), block); -======= - stage1.add(location, block); ->>>>>>> 399e0ad5... Refactor vector system to be cleaner +//<<<<<<< HEAD + stage1.put(location, block); +//======= +// stage1.add(location, block); +//>>>>>>> 399e0ad5... Refactor vector system to be cleaner return !existing.equalsFuzzy(block); } } @@ -152,17 +148,17 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder public Operation resume(RunContext run) throws WorldEditException { Extent extent = getExtent(); -<<<<<<< HEAD - final Set blocks = new HashSet<>(); - final Map blockTypes = new HashMap<>(); - for (Map.Entry entry : stage3) { - final BlockVector pt = entry.getKey(); -======= +//<<<<<<< HEAD final Set blocks = new HashSet<>(); final Map blockTypes = new HashMap<>(); - for (LocatedBlock entry : stage3) { - final BlockVector3 pt = entry.getLocation(); ->>>>>>> 399e0ad5... Refactor vector system to be cleaner + for (Map.Entry entry : stage3) { + final BlockVector3 pt = entry.getKey(); +//======= +// final Set blocks = new HashSet<>(); +// final Map blockTypes = new HashMap<>(); +// for (LocatedBlock entry : stage3) { +// final BlockVector3 pt = entry.getLocation(); +//>>>>>>> 399e0ad5... Refactor vector system to be cleaner blocks.add(pt); blockTypes.put(pt, entry.getValue()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/SetLocatedBlocks.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/SetLocatedBlocks.java new file mode 100644 index 000000000..cf644af7a --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/SetLocatedBlocks.java @@ -0,0 +1,56 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.function.operation; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.util.LocatedBlock; + +import java.util.List; + +public class SetLocatedBlocks implements Operation { + + private final Extent extent; + private final Iterable blocks; + + public SetLocatedBlocks(Extent extent, Iterable blocks) { + this.extent = checkNotNull(extent); + this.blocks = checkNotNull(blocks); + } + + @Override + public Operation resume(RunContext run) throws WorldEditException { + for (LocatedBlock block : blocks) { + extent.setBlock(block.getLocation(), block.getBlock()); + } + return null; + } + + @Override + public void cancel() { + } + + @Override + public void addStatusMessages(List messages) { + } + +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java new file mode 100644 index 000000000..ec06c27b5 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ArrayListHistory.java @@ -0,0 +1,73 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.history.changeset; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.collect.Lists; +import com.sk89q.worldedit.history.change.Change; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Stores all {@link Change}s in an {@link ArrayList}. + */ +public class ArrayListHistory implements ChangeSet { + + private final List changes = new ArrayList<>(); + + private boolean recordChanges = true; + + @Override + public void add(Change change) { + checkNotNull(change); + if (recordChanges) { + changes.add(change); + } + } + + @Override + public boolean isRecordingChanges() { + return recordChanges; + } + + @Override + public void setRecordChanges(boolean recordChanges) { + this.recordChanges = recordChanges; + } + + @Override + public Iterator backwardIterator() { + return Lists.reverse(changes).iterator(); + } + + @Override + public Iterator forwardIterator() { + return changes.iterator(); + } + + @Override + public int size() { + return changes.size(); + } + +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java index 0b018bcb9..24c4c3fe0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/ChangeSet.java @@ -36,6 +36,20 @@ public interface ChangeSet { */ void add(Change change); + /** + * Whether or not the ChangeSet is recording changes. + * + * @return whether or not the ChangeSet is set to record changes + */ + boolean isRecordingChanges(); + + /** + * Tell the change set whether to record changes or not. + * + * @param recordChanges whether to record changes or not + */ + void setRecordChanges(boolean recordChanges); + /** * Get a backward directed iterator that can be used for undo. * @@ -63,4 +77,4 @@ public interface ChangeSet { */ int size(); -} +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java index eafcb1728..de26f7776 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java @@ -27,6 +27,7 @@ import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @@ -150,6 +151,7 @@ public class ServerCUIHandler { structureTag.put("showboundingbox", new ByteTag((byte) 1)); structureTag.put("id", new StringTag(BlockTypes.STRUCTURE_BLOCK.getId())); - return BlockTypes.STRUCTURE_BLOCK.getDefaultState().toBaseBlock(new CompoundTag(structureTag)); +// return BlockTypes.STRUCTURE_BLOCK.getDefaultState().toBaseBlock(new CompoundTag(structureTag)); + return new BaseBlock(BlockTypes.STRUCTURE_BLOCK.getDefaultState(), new CompoundTag(structureTag)); } }