Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-03 01:50:07 +01:00
Added "fast mode corrections"
Dieser Commit ist enthalten in:
Ursprung
4e5e9f609e
Commit
7d468357e3
@ -448,6 +448,17 @@ public class BukkitWorld extends AbstractWorld {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean notifyAndLightBlock(BlockVector3 position, com.sk89q.worldedit.world.block.BlockState previousType) throws WorldEditException {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
adapter.notifyAndLightBlock(BukkitAdapter.adapt(getWorld(), position), previousType);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBiome getBiome(BlockVector2 position) {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
|
@ -24,6 +24,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import org.bukkit.Location;
|
||||
@ -78,6 +79,15 @@ public interface BukkitImplAdapter {
|
||||
*/
|
||||
boolean setBlock(Location location, BlockStateHolder state, boolean notifyAndLight);
|
||||
|
||||
/**
|
||||
* Notifies the simulation that the block at the given location has
|
||||
* been changed and it must be re-lighted (and issue other events).
|
||||
*
|
||||
* @param position position of the block
|
||||
* @param previousType the type of the previous block that was there
|
||||
*/
|
||||
void notifyAndLightBlock(Location position, BlockState previousType);
|
||||
|
||||
/**
|
||||
* Get the state for the given entity.
|
||||
*
|
||||
|
@ -170,6 +170,8 @@ public class EditSession implements Extent, AutoCloseable {
|
||||
private final Extent bypassHistory;
|
||||
private final Extent bypassNone;
|
||||
|
||||
private final boolean useFastModeCorrections;
|
||||
|
||||
private Mask oldMask;
|
||||
|
||||
/**
|
||||
@ -187,12 +189,13 @@ public class EditSession implements Extent, AutoCloseable {
|
||||
checkNotNull(event);
|
||||
|
||||
this.world = world;
|
||||
this.useFastModeCorrections = false;
|
||||
|
||||
if (world != null) {
|
||||
Extent extent;
|
||||
|
||||
// These extents are ALWAYS used
|
||||
extent = fastModeExtent = new FastModeExtent(world, false);
|
||||
extent = fastModeExtent = new FastModeExtent(world, useFastModeCorrections);
|
||||
extent = survivalExtent = new SurvivalModeExtent(extent, world);
|
||||
extent = quirkExtent = new BlockQuirkExtent(extent, world);
|
||||
extent = chunkLoadingExtent = new ChunkLoadingExtent(extent, world);
|
||||
@ -299,15 +302,17 @@ public class EditSession implements Extent, AutoCloseable {
|
||||
* @return whether the queue is enabled
|
||||
*/
|
||||
public boolean isQueueEnabled() {
|
||||
return reorderExtent.isEnabled();
|
||||
return !useFastModeCorrections && reorderExtent.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue certain types of block for better reproduction of those blocks.
|
||||
*/
|
||||
public void enableQueue() {
|
||||
if (!useFastModeCorrections) {
|
||||
reorderExtent.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the queue. This will {@linkplain #flushSession() flush the session}.
|
||||
@ -361,9 +366,16 @@ public class EditSession implements Extent, AutoCloseable {
|
||||
*/
|
||||
public void setFastMode(boolean enabled) {
|
||||
if (fastModeExtent != null) {
|
||||
// If fast mode corrections are enabled, we're using fast mode for
|
||||
// multipass support. Thus, we do not actually ever turn the fast mode
|
||||
// extent off, we instead toggle post edit simulation
|
||||
if (useFastModeCorrections) {
|
||||
fastModeExtent.setPostEditSimulationEnabled(!enabled);
|
||||
} else {
|
||||
fastModeExtent.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return fast mode status.
|
||||
|
@ -29,9 +29,12 @@ import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -40,8 +43,10 @@ import java.util.Set;
|
||||
public class FastModeExtent extends AbstractDelegateExtent {
|
||||
|
||||
private final World world;
|
||||
private final Queue<BlockVector3> positions = new ArrayDeque<>();
|
||||
private final Set<BlockVector2> dirtyChunks = new HashSet<>();
|
||||
private boolean enabled = true;
|
||||
private boolean postEditSimulation;
|
||||
|
||||
/**
|
||||
* Create a new instance with fast mode enabled.
|
||||
@ -63,6 +68,9 @@ public class FastModeExtent extends AbstractDelegateExtent {
|
||||
checkNotNull(world);
|
||||
this.world = world;
|
||||
this.enabled = enabled;
|
||||
if (enabled) {
|
||||
this.postEditSimulation = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,11 +91,27 @@ public class FastModeExtent extends AbstractDelegateExtent {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isPostEditSimulationEnabled() {
|
||||
return postEditSimulation;
|
||||
}
|
||||
|
||||
public void setPostEditSimulationEnabled(boolean enabled) {
|
||||
this.postEditSimulation = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
if (enabled) {
|
||||
dirtyChunks.add(BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4));
|
||||
return world.setBlock(location, block, false);
|
||||
|
||||
if (world.setBlock(location, block, false)) {
|
||||
if (postEditSimulation) {
|
||||
positions.offer(location);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return world.setBlock(location, block, true);
|
||||
}
|
||||
@ -101,6 +125,16 @@ public class FastModeExtent extends AbstractDelegateExtent {
|
||||
if (!dirtyChunks.isEmpty()) {
|
||||
world.fixAfterFastMode(dirtyChunks);
|
||||
}
|
||||
|
||||
if (postEditSimulation) {
|
||||
while (run.shouldContinue() && !positions.isEmpty()) {
|
||||
BlockVector3 position = positions.poll(); // Remove from queue
|
||||
world.notifyAndLightBlock(position, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
|
||||
return !positions.isEmpty() ? this : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ public interface ChangeSet {
|
||||
* @return whether or not the ChangeSet is set to record changes
|
||||
*/
|
||||
boolean isRecordingChanges();
|
||||
|
||||
/**
|
||||
* Tell the change set whether to record changes or not.
|
||||
*
|
||||
|
@ -64,6 +64,11 @@ public class NullWorld extends AbstractWorld {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLightLevel(BlockVector3 position) {
|
||||
return 0;
|
||||
|
@ -33,10 +33,13 @@ import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
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.weather.WeatherType;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Represents a world (dimension).
|
||||
*/
|
||||
@ -95,6 +98,16 @@ public interface World extends Extent {
|
||||
*/
|
||||
boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException;
|
||||
|
||||
/**
|
||||
* Notifies the simulation that the block at the given location has
|
||||
* been changed and it must be re-lighted (and issue other events).
|
||||
*
|
||||
* @param position position of the block
|
||||
* @param previousType the type of the previous block that was there
|
||||
* @return true if the block was successfully notified
|
||||
*/
|
||||
boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException;
|
||||
|
||||
/**
|
||||
* Get the light level at the given block.
|
||||
*
|
||||
|
@ -212,6 +212,12 @@ public class ForgeWorld extends AbstractWorld {
|
||||
return successful;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException {
|
||||
// TODO Implement
|
||||
return false;
|
||||
}
|
||||
|
||||
// Can't get the "Object" to be right for withProperty w/o this
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockState newState, Map<Property<?>, Object> states) {
|
||||
|
@ -41,7 +41,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.weather.WeatherType;
|
||||
import com.sk89q.worldedit.world.weather.WeatherTypes;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.block.BlockSnapshot;
|
||||
import org.spongepowered.api.block.BlockState;
|
||||
@ -163,6 +162,12 @@ public abstract class SpongeWorld extends AbstractWorld {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean notifyAndLightBlock(BlockVector3 position, com.sk89q.worldedit.world.block.BlockState previousType) throws WorldEditException {
|
||||
// TODO Move this to adapter
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean regenerate(Region region, EditSession editSession) {
|
||||
return false;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren