geforkt von Mirrors/FastAsyncWorldEdit
Added the multi-staging from the multipass2 branch
Dieser Commit ist enthalten in:
Ursprung
5acd0d8537
Commit
4e5e9f609e
@ -36,6 +36,28 @@ public final class Blocks {
|
|||||||
private Blocks() {
|
private Blocks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HashSet for shouldPlaceLate.
|
||||||
|
*/
|
||||||
|
private static final Set<BlockType> shouldPlaceLate = new HashSet<>();
|
||||||
|
static {
|
||||||
|
shouldPlaceLate.add(BlockTypes.WATER);
|
||||||
|
shouldPlaceLate.add(BlockTypes.LAVA);
|
||||||
|
shouldPlaceLate.add(BlockTypes.GRAVEL);
|
||||||
|
shouldPlaceLate.add(BlockTypes.SAND);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Checks to see whether a block should be placed in the final queue.
|
||||||
|
*
|
||||||
|
* This applies to blocks that can be attached to other blocks that have an attachment.
|
||||||
|
*
|
||||||
|
* @param type the type of the block
|
||||||
|
* @return whether the block is in the late queue
|
||||||
|
*/
|
||||||
|
public static boolean shouldPlaceLate(BlockType type) {
|
||||||
|
return shouldPlaceLate.contains(type);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HashSet for shouldPlaceLast.
|
* HashSet for shouldPlaceLast.
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.extent.reorder;
|
package com.sk89q.worldedit.extent.reorder;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.Blocks;
|
import com.sk89q.worldedit.blocks.Blocks;
|
||||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||||
@ -37,6 +36,7 @@ import com.sk89q.worldedit.world.block.BlockState;
|
|||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -50,11 +50,21 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class MultiStageReorder extends AbstractDelegateExtent implements ReorderingExtent {
|
public class MultiStageReorder extends AbstractDelegateExtent implements ReorderingExtent {
|
||||||
|
|
||||||
private LocatedBlockList stage1 = new LocatedBlockList();
|
private static final int STAGE_COUNT = 4;
|
||||||
private LocatedBlockList stage2 = new LocatedBlockList();
|
|
||||||
private LocatedBlockList stage3 = new LocatedBlockList();
|
private List<LocatedBlockList> stages = new ArrayList<>();
|
||||||
|
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance when the re-ordering is enabled.
|
||||||
|
*
|
||||||
|
* @param extent the extent
|
||||||
|
*/
|
||||||
|
public MultiStageReorder(Extent extent) {
|
||||||
|
this(extent, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*
|
*
|
||||||
@ -64,15 +74,10 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
|||||||
public MultiStageReorder(Extent extent, boolean enabled) {
|
public MultiStageReorder(Extent extent, boolean enabled) {
|
||||||
super(extent);
|
super(extent);
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
for (int i = 0; i < STAGE_COUNT; ++i) {
|
||||||
* Create a new instance when the re-ordering is enabled.
|
stages.add(new LocatedBlockList());
|
||||||
*
|
}
|
||||||
* @param extent the extent
|
|
||||||
*/
|
|
||||||
public MultiStageReorder(Extent extent) {
|
|
||||||
this(extent, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,58 +99,76 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean commitRequired() {
|
public boolean commitRequired() {
|
||||||
return stage1.size() > 0 || stage2.size() > 0 || stage3.size() > 0;
|
return stages.stream().anyMatch(stage -> stage.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the stage priority of the block.
|
||||||
|
*
|
||||||
|
* @param block The block
|
||||||
|
* @return The priority
|
||||||
|
*/
|
||||||
|
public int getPlacementPriority(BlockStateHolder block) {
|
||||||
|
if (Blocks.shouldPlaceLate(block.getBlockType())) {
|
||||||
|
return 1;
|
||||||
|
} else if (Blocks.shouldPlaceLast(block.getBlockType())) {
|
||||||
|
// Place torches, etc. last
|
||||||
|
return 2;
|
||||||
|
} else if (Blocks.shouldPlaceFinal(block.getBlockType())) {
|
||||||
|
// Place signs, reed, etc even later
|
||||||
|
return 3;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||||
BlockState existing = getBlock(location);
|
|
||||||
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return super.setBlock(location, block);
|
return super.setBlock(location, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Blocks.shouldPlaceLast(block.getBlockType())) {
|
BlockState existing = getBlock(location);
|
||||||
// Place torches, etc. last
|
int priority = getPlacementPriority(block);
|
||||||
stage2.add(location, block);
|
int srcPriority = getPlacementPriority(existing);
|
||||||
return !existing.equalsFuzzy(block);
|
|
||||||
} else if (Blocks.shouldPlaceFinal(block.getBlockType())) {
|
if (srcPriority == 1 || srcPriority == 2) {
|
||||||
// Place signs, reed, etc even later
|
|
||||||
stage3.add(location, block);
|
|
||||||
return !existing.equalsFuzzy(block);
|
|
||||||
} else if (Blocks.shouldPlaceLast(existing.getBlockType())) {
|
|
||||||
// Destroy torches, etc. first
|
// Destroy torches, etc. first
|
||||||
super.setBlock(location, BlockTypes.AIR.getDefaultState());
|
super.setBlock(location, BlockTypes.AIR.getDefaultState());
|
||||||
return super.setBlock(location, block);
|
return super.setBlock(location, block);
|
||||||
} else {
|
|
||||||
stage1.add(location, block);
|
|
||||||
return !existing.equalsFuzzy(block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stages.get(priority).add(location, block);
|
||||||
|
return !existing.equalsFuzzy(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation commitBefore() {
|
public Operation commitBefore() {
|
||||||
return new OperationQueue(
|
List<Operation> operations = new ArrayList<>();
|
||||||
new SetLocatedBlocks(
|
for (int i = 0; i < stages.size() - 1; ++i) {
|
||||||
getExtent(),
|
operations.add(new SetLocatedBlocks(getExtent(), stages.get(i)));
|
||||||
Iterables.concat(stage1, stage2)),
|
}
|
||||||
new Stage3Committer());
|
|
||||||
|
operations.add(new FinalStageCommitter());
|
||||||
|
return new OperationQueue(operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Stage3Committer implements Operation {
|
private class FinalStageCommitter implements Operation {
|
||||||
|
private Extent extent = getExtent();
|
||||||
|
|
||||||
@Override
|
private final Set<BlockVector3> blocks = new HashSet<>();
|
||||||
public Operation resume(RunContext run) throws WorldEditException {
|
private final Map<BlockVector3, BlockStateHolder> blockTypes = new HashMap<>();
|
||||||
Extent extent = getExtent();
|
|
||||||
|
|
||||||
final Set<BlockVector3> blocks = new HashSet<>();
|
public FinalStageCommitter() {
|
||||||
final Map<BlockVector3, BlockStateHolder> blockTypes = new HashMap<>();
|
for (LocatedBlock entry : stages.get(stages.size() - 1)) {
|
||||||
for (LocatedBlock entry : stage3) {
|
|
||||||
final BlockVector3 pt = entry.getLocation();
|
final BlockVector3 pt = entry.getLocation();
|
||||||
blocks.add(pt);
|
blocks.add(pt);
|
||||||
blockTypes.put(pt, entry.getBlock());
|
blockTypes.put(pt, entry.getBlock());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation resume(RunContext run) throws WorldEditException {
|
||||||
while (!blocks.isEmpty()) {
|
while (!blocks.isEmpty()) {
|
||||||
BlockVector3 current = blocks.iterator().next();
|
BlockVector3 current = blocks.iterator().next();
|
||||||
if (!blocks.contains(current)) {
|
if (!blocks.contains(current)) {
|
||||||
@ -201,11 +224,14 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage1.clear();
|
if (blocks.isEmpty()) {
|
||||||
stage2.clear();
|
for (LocatedBlockList stage : stages) {
|
||||||
stage3.clear();
|
stage.clear();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,10 +35,24 @@ public class ArrayListHistory implements ChangeSet {
|
|||||||
|
|
||||||
private final List<Change> changes = new ArrayList<>();
|
private final List<Change> changes = new ArrayList<>();
|
||||||
|
|
||||||
|
private boolean recordChanges = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Change change) {
|
public void add(Change change) {
|
||||||
checkNotNull(change);
|
checkNotNull(change);
|
||||||
changes.add(change);
|
if (recordChanges) {
|
||||||
|
changes.add(change);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRecordingChanges() {
|
||||||
|
return recordChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRecordChanges(boolean recordChanges) {
|
||||||
|
this.recordChanges = recordChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,6 +36,19 @@ public interface ChangeSet {
|
|||||||
*/
|
*/
|
||||||
void add(Change change);
|
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.
|
* Get a backward directed iterator that can be used for undo.
|
||||||
*
|
*
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren