mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 04:38:35 +00:00
Further work on this. Currently fast mode breaks doors, gotta work out why applying physics to doors breaks them.
This commit is contained in:
@ -20,7 +20,6 @@
|
||||
package com.sk89q.worldedit.extent.reorder;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.Blocks;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
@ -34,6 +33,7 @@ import com.sk89q.worldedit.util.collection.LocatedBlockList;
|
||||
import com.sk89q.worldedit.world.block.BlockCategories;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -50,12 +50,112 @@ import java.util.Set;
|
||||
*/
|
||||
public class MultiStageReorder extends AbstractDelegateExtent implements ReorderingExtent {
|
||||
|
||||
private static final int STAGE_COUNT = 4;
|
||||
private static Map<BlockType, PlacementPriority> priorityMap = new HashMap<>();
|
||||
|
||||
private List<LocatedBlockList> stages = new ArrayList<>();
|
||||
static {
|
||||
// Late
|
||||
priorityMap.put(BlockTypes.WATER, PlacementPriority.LATE);
|
||||
priorityMap.put(BlockTypes.LAVA, PlacementPriority.LATE);
|
||||
priorityMap.put(BlockTypes.SAND, PlacementPriority.LATE);
|
||||
priorityMap.put(BlockTypes.GRAVEL, PlacementPriority.LATE);
|
||||
|
||||
// Late
|
||||
BlockCategories.SAPLINGS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.LAST));
|
||||
BlockCategories.FLOWER_POTS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.LAST));
|
||||
BlockCategories.BUTTONS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.LAST));
|
||||
BlockCategories.ANVIL.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.LAST));
|
||||
BlockCategories.WOODEN_PRESSURE_PLATES.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.LAST));
|
||||
BlockCategories.CARPETS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.LAST));
|
||||
BlockCategories.RAILS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.LAST));
|
||||
priorityMap.put(BlockTypes.BLACK_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.BLUE_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.BROWN_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.CYAN_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.GRAY_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.GREEN_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.LIGHT_BLUE_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.LIGHT_GRAY_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.LIME_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.MAGENTA_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.ORANGE_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.PINK_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.PURPLE_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.RED_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.WHITE_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.YELLOW_BED, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.GRASS, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.TALL_GRASS, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.ROSE_BUSH, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.DANDELION, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.BROWN_MUSHROOM, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.RED_MUSHROOM, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.FERN, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.LARGE_FERN, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.OXEYE_DAISY, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.AZURE_BLUET, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.TORCH, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.WALL_TORCH, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.FIRE, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.REDSTONE_WIRE, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.CARROTS, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.POTATOES, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.WHEAT, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.BEETROOTS, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.COCOA, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.LADDER, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.LEVER, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.REDSTONE_TORCH, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.REDSTONE_WALL_TORCH, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.SNOW, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.NETHER_PORTAL, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.END_PORTAL, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.REPEATER, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.VINE, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.LILY_PAD, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.NETHER_WART, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.PISTON, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.STICKY_PISTON, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.TRIPWIRE_HOOK, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.TRIPWIRE, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.STONE_PRESSURE_PLATE, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.COMPARATOR, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.IRON_TRAPDOOR, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.ACACIA_TRAPDOOR, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.BIRCH_TRAPDOOR, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.DARK_OAK_TRAPDOOR, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.JUNGLE_TRAPDOOR, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.OAK_TRAPDOOR, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.SPRUCE_TRAPDOOR, PlacementPriority.LAST);
|
||||
priorityMap.put(BlockTypes.DAYLIGHT_DETECTOR, PlacementPriority.LAST);
|
||||
|
||||
// Final
|
||||
BlockCategories.DOORS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.FINAL));
|
||||
BlockCategories.BANNERS.getAll().forEach(type -> priorityMap.put(type, PlacementPriority.FINAL));
|
||||
priorityMap.put(BlockTypes.SIGN, PlacementPriority.FINAL);
|
||||
priorityMap.put(BlockTypes.WALL_SIGN, PlacementPriority.FINAL);
|
||||
priorityMap.put(BlockTypes.CACTUS, PlacementPriority.FINAL);
|
||||
priorityMap.put(BlockTypes.SUGAR_CANE, PlacementPriority.FINAL);
|
||||
priorityMap.put(BlockTypes.CAKE, PlacementPriority.FINAL);
|
||||
priorityMap.put(BlockTypes.PISTON_HEAD, PlacementPriority.FINAL);
|
||||
priorityMap.put(BlockTypes.MOVING_PISTON, PlacementPriority.FINAL);
|
||||
}
|
||||
|
||||
private Map<PlacementPriority, LocatedBlockList> stages = new HashMap<>();
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public enum PlacementPriority {
|
||||
CLEAR_FINAL,
|
||||
CLEAR_LAST,
|
||||
CLEAR_LATE,
|
||||
FIRST,
|
||||
LATE,
|
||||
LAST,
|
||||
FINAL
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance when the re-ordering is enabled.
|
||||
*
|
||||
@ -75,8 +175,8 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
super(extent);
|
||||
this.enabled = enabled;
|
||||
|
||||
for (int i = 0; i < STAGE_COUNT; ++i) {
|
||||
stages.add(new LocatedBlockList());
|
||||
for (PlacementPriority priority : PlacementPriority.values()) {
|
||||
stages.put(priority, new LocatedBlockList());
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +199,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
}
|
||||
|
||||
public boolean commitRequired() {
|
||||
return enabled && stages.stream().anyMatch(stage -> stage.size() > 0);
|
||||
return enabled && stages.values().stream().anyMatch(stage -> stage.size() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,18 +208,8 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
* @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;
|
||||
}
|
||||
private PlacementPriority getPlacementPriority(BlockStateHolder block) {
|
||||
return priorityMap.getOrDefault(block.getBlockType(), PlacementPriority.FIRST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,13 +219,27 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
}
|
||||
|
||||
BlockState existing = getBlock(location);
|
||||
int priority = getPlacementPriority(block);
|
||||
int srcPriority = getPlacementPriority(existing);
|
||||
PlacementPriority priority = getPlacementPriority(block);
|
||||
PlacementPriority srcPriority = getPlacementPriority(existing);
|
||||
|
||||
if (srcPriority == 1 || srcPriority == 2) {
|
||||
// Destroy torches, etc. first
|
||||
super.setBlock(location, BlockTypes.AIR.getDefaultState());
|
||||
return super.setBlock(location, block);
|
||||
if (srcPriority != PlacementPriority.FIRST) {
|
||||
BlockStateHolder replacement = block.getBlockType().getMaterial().isAir() ? block : BlockTypes.AIR.getDefaultState();
|
||||
|
||||
switch (srcPriority) {
|
||||
case FINAL:
|
||||
stages.get(PlacementPriority.CLEAR_FINAL).add(location, replacement);
|
||||
break;
|
||||
case LATE:
|
||||
stages.get(PlacementPriority.CLEAR_LATE).add(location, replacement);
|
||||
break;
|
||||
case LAST:
|
||||
stages.get(PlacementPriority.CLEAR_LAST).add(location, replacement);
|
||||
break;
|
||||
}
|
||||
|
||||
if (block.getBlockType().getMaterial().isAir()) {
|
||||
return !existing.equalsFuzzy(block);
|
||||
}
|
||||
}
|
||||
|
||||
stages.get(priority).add(location, block);
|
||||
@ -144,9 +248,14 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
|
||||
@Override
|
||||
public Operation commitBefore() {
|
||||
if (!enabled) {
|
||||
return null;
|
||||
}
|
||||
List<Operation> operations = new ArrayList<>();
|
||||
for (int i = 0; i < stages.size() - 1; ++i) {
|
||||
operations.add(new SetLocatedBlocks(getExtent(), stages.get(i)));
|
||||
for (PlacementPriority priority : PlacementPriority.values()) {
|
||||
if (priority != PlacementPriority.FINAL) {
|
||||
operations.add(new SetLocatedBlocks(getExtent(), stages.get(priority)));
|
||||
}
|
||||
}
|
||||
|
||||
operations.add(new FinalStageCommitter());
|
||||
@ -160,7 +269,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
private final Map<BlockVector3, BlockStateHolder> blockTypes = new HashMap<>();
|
||||
|
||||
public FinalStageCommitter() {
|
||||
for (LocatedBlock entry : stages.get(stages.size() - 1)) {
|
||||
for (LocatedBlock entry : stages.get(PlacementPriority.FINAL)) {
|
||||
final BlockVector3 pt = entry.getLocation();
|
||||
blocks.add(pt);
|
||||
blockTypes.put(pt, entry.getBlock());
|
||||
@ -171,9 +280,6 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
while (!blocks.isEmpty()) {
|
||||
BlockVector3 current = blocks.iterator().next();
|
||||
if (!blocks.contains(current)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Deque<BlockVector3> walked = new LinkedList<>();
|
||||
|
||||
@ -224,14 +330,10 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
}
|
||||
}
|
||||
|
||||
if (blocks.isEmpty()) {
|
||||
for (LocatedBlockList stage : stages) {
|
||||
stage.clear();
|
||||
}
|
||||
return null;
|
||||
for (LocatedBlockList stage : stages.values()) {
|
||||
stage.clear();
|
||||
}
|
||||
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,11 +114,14 @@ public class FastModeExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
public boolean commitRequired() {
|
||||
return !dirtyChunks.isEmpty() || !positions.isEmpty();
|
||||
return (enabled && !dirtyChunks.isEmpty()) || (postEditSimulation && !positions.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Operation commitBefore() {
|
||||
if (!enabled && !postEditSimulation) {
|
||||
return null;
|
||||
}
|
||||
return new Operation() {
|
||||
@Override
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
|
Reference in New Issue
Block a user