3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-24 18:10:08 +01:00

Added "fast mode corrections"

Dieser Commit ist enthalten in:
Matthew Miller 2018-10-15 20:50:09 +10:00 committet von IronApollo
Ursprung 346eee8953
Commit e88b8c961d
10 geänderte Dateien mit 101 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -487,6 +487,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 @Override
public BaseBiome getBiome(BlockVector2 position) { public BaseBiome getBiome(BlockVector2 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();

Datei anzeigen

@ -27,6 +27,7 @@ import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property; 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.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
@ -79,6 +80,15 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
boolean isChunkInUse(Chunk chunk); boolean isChunkInUse(Chunk chunk);
/**
* 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. * Get the state for the given entity.
* *

Datei anzeigen

@ -254,4 +254,9 @@ public class WorldWrapper extends AbstractWorld {
public boolean setBiome(BlockVector2 position, BaseBiome biome) { public boolean setBiome(BlockVector2 position, BaseBiome biome) {
return parent.setBiome(position, biome); return parent.setBiome(position, biome);
} }
@Override
public boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException {
return parent.notifyAndLightBlock(position, previousType);
}
} }

Datei anzeigen

@ -377,6 +377,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
this(WorldEdit.getInstance().getEventBus(), world, maxBlocks, blockBag, new EditSessionEvent(world, null, maxBlocks, null)); this(WorldEdit.getInstance().getEventBus(), world, maxBlocks, blockBag, new EditSessionEvent(world, null, maxBlocks, null));
} }
private Mask oldMask;
/** /**
* Construct the object with a maximum number of blocks and a block bag. * Construct the object with a maximum number of blocks and a block bag.
* *
@ -3589,14 +3591,17 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
@Override @Override
public void dropItem(Vector3 position, BaseItemStack item) { public void dropItem(Vector3 position, BaseItemStack item) {
// TODO Auto-generated method stub world.dropItem(position, item);
} }
@Override @Override
public boolean playEffect(Vector3 position, int type, int data) { public boolean playEffect(Vector3 position, int type, int data) {
// TODO Auto-generated method stub return world.playEffect(position, type, data);
return false; }
@Override
public boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException {
return world.notifyAndLightBlock(position, previousType);
} }
} }

Datei anzeigen

@ -29,9 +29,12 @@ import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.HashSet;
import java.util.List; import java.util.List;
import java.util.Queue;
import java.util.Set; import java.util.Set;
/** /**
@ -40,8 +43,10 @@ import java.util.Set;
public class FastModeExtent extends AbstractDelegateExtent { public class FastModeExtent extends AbstractDelegateExtent {
private final World world; private final World world;
private final Queue<BlockVector3> positions = new ArrayDeque<>();
private final Set<BlockVector2> dirtyChunks = new HashSet<>(); private final Set<BlockVector2> dirtyChunks = new HashSet<>();
private boolean enabled = true; private boolean enabled = true;
private boolean postEditSimulation;
/** /**
* Create a new instance with fast mode enabled. * Create a new instance with fast mode enabled.
@ -63,6 +68,9 @@ public class FastModeExtent extends AbstractDelegateExtent {
checkNotNull(world); checkNotNull(world);
this.world = world; this.world = world;
this.enabled = enabled; this.enabled = enabled;
if (enabled) {
this.postEditSimulation = true;
}
} }
/** /**
@ -83,11 +91,27 @@ public class FastModeExtent extends AbstractDelegateExtent {
this.enabled = enabled; this.enabled = enabled;
} }
public boolean isPostEditSimulationEnabled() {
return postEditSimulation;
}
public void setPostEditSimulationEnabled(boolean enabled) {
this.postEditSimulation = enabled;
}
@Override @Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
if (enabled) { if (enabled) {
dirtyChunks.add(BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4)); 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 { } else {
return world.setBlock(location, block, true); return world.setBlock(location, block, true);
} }
@ -101,6 +125,16 @@ public class FastModeExtent extends AbstractDelegateExtent {
if (!dirtyChunks.isEmpty()) { if (!dirtyChunks.isEmpty()) {
world.fixAfterFastMode(dirtyChunks); 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; return null;
} }

Datei anzeigen

@ -42,7 +42,7 @@ public interface ChangeSet {
* @return whether or not the ChangeSet is set to record changes * @return whether or not the ChangeSet is set to record changes
*/ */
boolean isRecordingChanges(); boolean isRecordingChanges();
/** /**
* Tell the change set whether to record changes or not. * Tell the change set whether to record changes or not.
* *

Datei anzeigen

@ -64,6 +64,11 @@ public class NullWorld extends AbstractWorld {
return false; return false;
} }
@Override
public boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException {
return false;
}
@Override @Override
public int getBlockLightLevel(BlockVector3 position) { public int getBlockLightLevel(BlockVector3 position) {
return 0; return 0;

Datei anzeigen

@ -33,10 +33,13 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.TreeGenerator; 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.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherType;
import java.util.Vector;
/** /**
* Represents a world (dimension). * Represents a world (dimension).
*/ */
@ -95,6 +98,16 @@ public interface World extends Extent {
*/ */
boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException; 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. * Get the light level at the given block.
* *

Datei anzeigen

@ -214,6 +214,12 @@ public class ForgeWorld extends AbstractWorld {
return successful; 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 // Can't get the "Object" to be right for withProperty w/o this
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockState newState, Map<Property<?>, Object> states) { private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockState newState, Map<Property<?>, Object> states) {

Datei anzeigen

@ -42,7 +42,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldedit.world.weather.WeatherTypes; import com.sk89q.worldedit.world.weather.WeatherTypes;
import org.spongepowered.api.Sponge; import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockState;
@ -164,6 +163,12 @@ public abstract class SpongeWorld extends AbstractWorld {
return true; 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 @Override
public boolean regenerate(Region region, EditSession editSession) { public boolean regenerate(Region region, EditSession editSession) {
return false; return false;