Dieser Commit ist enthalten in:
Jesse Boyd 2019-07-09 17:18:51 +10:00
Commit f99d6e7478
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
229 geänderte Dateien mit 9489 neuen und 3025 gelöschten Zeilen

Datei anzeigen

@ -18,31 +18,39 @@ configurations.all { Configuration it ->
} }
} }
task downloadJarsToLibs(){
def f = new File('lib/spigot-1.14.jar')
if (!f.exists()) {
new URL('https://ci.athion.net/job/BuildTools/lastSuccessfulBuild/artifact/spigot-1.14.jar').withInputStream{ i -> f.withOutputStream{ it << i }}
}
}
dependencies { dependencies {
api project(':worldedit-core') api project(':worldedit-core')
api project(':worldedit-libs:bukkit') api project(':worldedit-libs:bukkit')
compile 'net.milkbowl.vault:VaultAPI:1.7'
compile 'com.destroystokyo.paper:paper-api:1.14.3-R0.1-SNAPSHOT'
implementation 'io.papermc:paperlib:1.0.2'
compileOnly 'com.sk89q:dummypermscompat:1.10' compileOnly 'com.sk89q:dummypermscompat:1.10'
testCompile 'org.mockito:mockito-core:1.9.0-rc1'
implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1'){transitive = false}
compile 'com.destroystokyo.paper:paper-api:1.14.3-R0.1-SNAPSHOT'
implementation('io.papermc:paperlib:1.0.2'){transitive = false}
compile 'org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT' compile 'org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT'
compile name: 'spigot-1.14.3' compile name: 'spigot-1.14.3'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.8.1' // compile([fileTree(dir: 'lib', include: ['*.jar']),'commons-validator:commons-validator:1.4.1'])
testCompile 'org.mockito:mockito-core:1.9.0-rc1' implementation('com.sk89q.worldguard:worldguard-core:7.0.0-20190215.210421-39'){transitive = false}
compile 'com.massivecraft:factions:2.8.0' implementation('com.sk89q.worldguard:worldguard-legacy:7.0.0-20190215.210421-39'){transitive = false}
compile 'com.drtshock:factions:1.6.9.5' implementation('net.milkbowl.vault:VaultAPI:1.7'){transitive = false}
compile 'com.factionsone:FactionsOne:1.2.2' implementation('com.massivecraft:factions:2.8.0'){transitive = false}
compile 'me.ryanhamshire:GriefPrevention:11.5.2' implementation('com.drtshock:factions:1.6.9.5'){transitive = false}
compile 'com.massivecraft:mcore:7.0.1' implementation('com.factionsone:FactionsOne:1.2.2'){transitive = false}
compile 'net.sacredlabyrinth.Phaed:PreciousStones:10.0.4-SNAPSHOT' implementation('me.ryanhamshire:GriefPrevention:11.5.2'){transitive = false}
compile 'net.jzx7:regios:5.9.9' implementation('com.massivecraft:mcore:7.0.1'){transitive = false}
compile 'com.bekvon.bukkit.residence:Residence:4.5._13.1' implementation('net.sacredlabyrinth.Phaed:PreciousStones:10.0.4-SNAPSHOT'){transitive = false}
compile 'com.palmergames.bukkit:towny:0.84.0.9' implementation('net.jzx7:regios:5.9.9'){transitive = false}
compile 'com.thevoxelbox.voxelsniper:voxelsniper:5.171.0' implementation('com.bekvon.bukkit.residence:Residence:4.5._13.1'){transitive = false}
compile 'com.comphenix.protocol:ProtocolLib-API:4.4.0-SNAPSHOT' implementation('com.palmergames.bukkit:towny:0.84.0.9'){transitive = false}
compile 'com.wasteofplastic:askyblock:3.0.8.2' implementation('com.thevoxelbox.voxelsniper:voxelsniper:5.171.0'){transitive = false}
compileOnly 'com.sk89q.worldguard:worldguard-core:7.0.0-20190215.210421-39' implementation('com.comphenix.protocol:ProtocolLib-API:4.4.0-SNAPSHOT'){transitive = false}
compileOnly 'com.sk89q.worldguard:worldguard-legacy:7.0.0-20190215.210421-39' implementation('com.wasteofplastic:askyblock:3.0.8.2'){transitive = false}
} }
processResources { processResources {

Datei anzeigen

@ -2,6 +2,9 @@ package com.boydti.fawe.bukkit;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.IFawe; import com.boydti.fawe.IFawe;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.bukkit.beta.BukkitQueue;
import com.boydti.fawe.bukkit.beta.BukkitQueueHandler;
import com.boydti.fawe.bukkit.chat.BukkitChatManager; import com.boydti.fawe.bukkit.chat.BukkitChatManager;
import com.boydti.fawe.bukkit.listener.AsyncTabCompleteListener; import com.boydti.fawe.bukkit.listener.AsyncTabCompleteListener;
import com.boydti.fawe.bukkit.listener.BrushListener; import com.boydti.fawe.bukkit.listener.BrushListener;
@ -30,6 +33,7 @@ import com.boydti.fawe.bukkit.v0.BukkitQueue_All;
import com.boydti.fawe.bukkit.v0.ChunkListener_8; import com.boydti.fawe.bukkit.v0.ChunkListener_8;
import com.boydti.fawe.bukkit.v0.ChunkListener_9; import com.boydti.fawe.bukkit.v0.ChunkListener_9;
import com.boydti.fawe.bukkit.v1_13.BukkitQueue_1_13; import com.boydti.fawe.bukkit.v1_13.BukkitQueue_1_13;
import com.boydti.fawe.bukkit.v1_14.BukkitQueue_1_14;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FaweCommand;
@ -43,6 +47,7 @@ import com.boydti.fawe.util.image.ImageViewer;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -50,9 +55,11 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -150,6 +157,11 @@ public class FaweBukkit implements IFawe, Listener {
// } // }
// } // }
@Override
public QueueHandler getQueueHandler() {
return new BukkitQueueHandler();
}
@Override @Override
public synchronized ImageViewer getImageViewer(FawePlayer fp) { public synchronized ImageViewer getImageViewer(FawePlayer fp) {
if (listeningImages && imageListener == null) return null; if (listeningImages && imageListener == null) return null;
@ -575,6 +587,7 @@ public class FaweBukkit implements IFawe, Listener {
} }
public enum Version { public enum Version {
v1_14_R1,
v1_13_R2, v1_13_R2,
NONE, NONE,
} }
@ -583,6 +596,8 @@ public class FaweBukkit implements IFawe, Listener {
switch (getVersion()) { switch (getVersion()) {
case v1_13_R2: case v1_13_R2:
return new BukkitQueue_1_13(world); return new BukkitQueue_1_13(world);
case v1_14_R1:
return new BukkitQueue_1_14(world);
default: default:
case NONE: case NONE:
return new BukkitQueue_All(world); return new BukkitQueue_All(world);
@ -593,6 +608,8 @@ public class FaweBukkit implements IFawe, Listener {
switch (getVersion()) { switch (getVersion()) {
case v1_13_R2: case v1_13_R2:
return new BukkitQueue_1_13(world); return new BukkitQueue_1_13(world);
case v1_14_R1:
return new BukkitQueue_1_14(world);
default: default:
case NONE: case NONE:
return new BukkitQueue_All(world); return new BukkitQueue_All(world);

Datei anzeigen

@ -102,16 +102,16 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
nbtCreateTagMethod.setAccessible(true); nbtCreateTagMethod.setAccessible(true);
} }
public int[] idbToStateOrdinal; public char[] idbToStateOrdinal;
private boolean init() { private synchronized boolean init() {
if (idbToStateOrdinal != null) return false; if (idbToStateOrdinal != null) return false;
idbToStateOrdinal = new int[Block.REGISTRY_ID.a()]; // size idbToStateOrdinal = new char[Block.REGISTRY_ID.a()]; // size
for (int i = 0; i < idbToStateOrdinal.length; i++) { for (int i = 0; i < idbToStateOrdinal.length; i++) {
BlockState state = BlockTypes.states[i]; BlockState state = BlockTypes.states[i];
BlockMaterial_1_13 material = (BlockMaterial_1_13) state.getMaterial(); BlockMaterial_1_13 material = (BlockMaterial_1_13) state.getMaterial();
int id = Block.REGISTRY_ID.getId(material.getState()); int id = Block.REGISTRY_ID.getId(material.getState());
idbToStateOrdinal[id] = state.getOrdinal(); idbToStateOrdinal[id] = state.getOrdinalChar();
} }
return true; return true;
} }
@ -533,8 +533,18 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
int id = Block.REGISTRY_ID.getId(ibd); int id = Block.REGISTRY_ID.getId(ibd);
return idbToStateOrdinal[id]; return idbToStateOrdinal[id];
} catch (NullPointerException e) { } catch (NullPointerException e) {
if (init()) return adaptToInt(ibd); init();
throw e; return adaptToInt(ibd);
}
}
public char adaptToChar(IBlockData ibd) {
try {
int id = Block.REGISTRY_ID.getId(ibd);
return idbToStateOrdinal[id];
} catch (NullPointerException e) {
init();
return adaptToChar(ibd);
} }
} }

Datei anzeigen

@ -0,0 +1,352 @@
package com.boydti.fawe.bukkit.beta;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.beta.implementation.holder.ChunkHolder;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.bukkit.v1_13.BukkitQueue_1_13;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.world.biome.BiomeType;
import net.minecraft.server.v1_14_R1.BiomeBase;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.Chunk;
import net.minecraft.server.v1_14_R1.ChunkSection;
import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.MinecraftKey;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.NBTTagInt;
import net.minecraft.server.v1_14_R1.TileEntity;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
public class BukkitChunkHolder<T extends Future<T>> extends ChunkHolder {
@Override
public void init(final IQueueExtent extent, final int X, final int Z) {
super.init(extent, X, Z);
}
@Override
public IChunkGet get() {
BukkitQueue extent = (BukkitQueue) getExtent();
return new BukkitGetBlocks(extent.getNmsWorld(), getX(), getZ(), MemUtil.isMemoryFree());
}
private void updateGet(BukkitGetBlocks get, Chunk nmsChunk, ChunkSection[] sections, ChunkSection section, char[] arr, int layer) {
synchronized (get) {
if (get.nmsChunk != nmsChunk) {
get.nmsChunk = nmsChunk;
get.sections = sections.clone();
get.reset();
}
if (get.sections == null) {
get.sections = sections.clone();
}
if (get.sections[layer] != section) {
get.sections[layer] = section;
}
get.blocks[layer] = arr;
}
}
@Override
public synchronized T call() {
try {
int X = getX();
int Z = getZ();
BukkitQueue extent = (BukkitQueue) getExtent();
BukkitGetBlocks get = (BukkitGetBlocks) getOrCreateGet();
IChunkSet set = getOrCreateSet();
Chunk nmsChunk = extent.ensureLoaded(X, Z);
// Remove existing tiles
{
Map<BlockPosition, TileEntity> tiles = nmsChunk.getTileEntities();
if (!tiles.isEmpty()) {
final Iterator<Map.Entry<BlockPosition, TileEntity>> iterator = tiles.entrySet().iterator();
while (iterator.hasNext()) {
final Map.Entry<BlockPosition, TileEntity> entry = iterator.next();
final BlockPosition pos = entry.getKey();
final int lx = pos.getX() & 15;
final int ly = pos.getY();
final int lz = pos.getZ() & 15;
final int layer = ly >> 4;
if (!set.hasSection(layer)) {
continue;
}
if (set.getBlock(lx, ly, lz).getOrdinal() != 0) {
TileEntity tile = entry.getValue();
tile.z();
tile.invalidateBlockCache();
}
}
}
}
int bitMask = 0;
synchronized (nmsChunk) {
ChunkSection[] sections = nmsChunk.getSections();
World world = extent.getBukkitWorld();
boolean hasSky = world.getEnvironment() == World.Environment.NORMAL;
for (int layer = 0; layer < 16; layer++) {
if (!set.hasSection(layer)) continue;
bitMask |= 1 << layer;
char[] setArr = set.getArray(layer);
ChunkSection newSection;
ChunkSection existingSection = sections[layer];
if (existingSection == null) {
newSection = extent.newChunkSection(layer, hasSky, setArr);
if (BukkitQueue.setSectionAtomic(sections, null, newSection, layer)) {
updateGet(get, nmsChunk, sections, newSection, setArr, layer);
continue;
} else {
existingSection = sections[layer];
if (existingSection == null) {
System.out.println("Skipping invalid null section. chunk:" + X + "," + Z + " layer: " + layer);
continue;
}
}
}
DelegateLock lock = BukkitQueue.applyLock(existingSection);
synchronized (get) {
synchronized (lock) {
lock.untilFree();
ChunkSection getSection;
if (get.nmsChunk != nmsChunk) {
get.nmsChunk = nmsChunk;
get.sections = null;
get.reset();
} else {
getSection = get.getSections()[layer];
if (getSection != existingSection) {
get.sections[layer] = existingSection;
get.reset();
} else if (lock.isModified()) {
get.reset(layer);
}
}
char[] getArr = get.load(layer);
for (int i = 0; i < 4096; i++) {
char value = setArr[i];
if (value != 0) {
getArr[i] = value;
}
}
newSection = extent.newChunkSection(layer, hasSky, getArr);
if (!BukkitQueue.setSectionAtomic(sections, existingSection, newSection, layer)) {
System.out.println("Failed to set chunk section:" + X + "," + Z + " layer: " + layer);
continue;
} else {
updateGet(get, nmsChunk, sections, newSection, setArr, layer);
}
}
}
}
// Biomes
BiomeType[] biomes = set.getBiomes();
if (biomes != null) {
// set biomes
final BiomeBase[] currentBiomes = nmsChunk.getBiomeIndex();
for (int i = 0; i < biomes.length; i++) {
final BiomeType biome = biomes[i];
if (biome != null) {
final Biome craftBiome = BukkitAdapter.adapt(biome);
currentBiomes[i] = CraftBlock.biomeToBiomeBase(craftBiome);
}
}
}
Runnable[] syncTasks = null;
net.minecraft.server.v1_14_R1.World nmsWorld = nmsChunk.getWorld();
int bx = X << 4;
int bz = Z << 4;
Set<UUID> entityRemoves = set.getEntityRemoves();
if (entityRemoves != null && !entityRemoves.isEmpty()) {
if (syncTasks == null) syncTasks = new Runnable[3];
syncTasks[2] = new Runnable() {
@Override
public void run() {
final List<Entity>[] entities = nmsChunk.getEntitySlices();
for (int i = 0; i < entities.length; i++) {
final Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
final Iterator<Entity> iter = ents.iterator();
while (iter.hasNext()) {
final Entity entity = iter.next();
if (entityRemoves.contains(entity.getUniqueID())) {
iter.remove();
entity.b(false);
entity.die();
entity.valid = false;
}
}
}
}
}
};
}
Set<CompoundTag> entities = set.getEntities();
if (entities != null && !entities.isEmpty()) {
if (syncTasks == null) syncTasks = new Runnable[2];
syncTasks[1] = new Runnable() {
@Override
public void run() {
for (final CompoundTag nativeTag : entities) {
final Map<String, Tag> entityTagMap = ReflectionUtils.getMap(nativeTag.getValue());
final StringTag idTag = (StringTag) entityTagMap.get("Id");
final ListTag posTag = (ListTag) entityTagMap.get("Pos");
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation");
if (idTag == null || posTag == null || rotTag == null) {
Fawe.debug("Unknown entity tag: " + nativeTag);
continue;
}
final double x = posTag.getDouble(0);
final double y = posTag.getDouble(1);
final double z = posTag.getDouble(2);
final float yaw = rotTag.getFloat(0);
final float pitch = rotTag.getFloat(1);
final String id = idTag.getValue();
final Entity entity = EntityTypes.a(nmsWorld, new MinecraftKey(id));
if (entity != null) {
final UUID uuid = entity.getUniqueID();
entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
if (nativeTag != null) {
final NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_13.fromNative(nativeTag);
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
entity.f(tag);
}
entity.setLocation(x, y, z, yaw, pitch);
nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
}
}
};
}
// set tiles
Map<Short, CompoundTag> tiles = set.getTiles();
if (tiles != null && !tiles.isEmpty()) {
if (syncTasks == null) syncTasks = new Runnable[1];
syncTasks[0] = new Runnable() {
@Override
public void run() {
for (final Map.Entry<Short, CompoundTag> entry : tiles.entrySet()) {
final CompoundTag nativeTag = entry.getValue();
final short blockHash = entry.getKey();
final int x = (blockHash >> 12 & 0xF) + bx;
final int y = (blockHash & 0xFF);
final int z = (blockHash >> 8 & 0xF) + bz;
final BlockPosition pos = new BlockPosition(x, y, z);
synchronized (BukkitQueue_0.class) {
TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity == null || tileEntity.x()) {
nmsWorld.n(pos);
tileEntity = nmsWorld.getTileEntity(pos);
}
if (tileEntity != null) {
final NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_13.fromNative(nativeTag);
tag.set("x", new NBTTagInt(x));
tag.set("y", new NBTTagInt(y));
tag.set("z", new NBTTagInt(z));
tileEntity.load(tag);
}
}
}
}
};
}
Runnable callback;
if (bitMask == 0) {
callback = null;
} else {
int finalMask = bitMask;
callback = () -> {
// Set Modified
nmsChunk.f(true);
nmsChunk.mustSave = true;
nmsChunk.markDirty();
// send to player
extent.sendChunk(X, Z, finalMask);
extent.returnToPool(BukkitChunkHolder.this);
};
}
if (syncTasks != null) {
QueueHandler queueHandler = Fawe.get().getQueueHandler();
Runnable[] finalSyncTasks = syncTasks;
// Chain the sync tasks and the callback
Callable<Future> chain = new Callable<Future>() {
@Override
public Future call() {
// Run the sync tasks
for (int i = 1; i < finalSyncTasks.length; i++) {
Runnable task = finalSyncTasks[i];
if (task != null) {
task.run();
}
}
if (callback == null) {
extent.returnToPool(BukkitChunkHolder.this);
return null;
} else {
return queueHandler.async(callback, null);
}
}
};
return (T) (Future) queueHandler.sync(chain);
} else {
if (callback == null) {
extent.returnToPool(BukkitChunkHolder.this);
} else {
callback.run();
}
}
}
return null;
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}

Datei anzeigen

@ -0,0 +1,208 @@
package com.boydti.fawe.bukkit.beta;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import com.boydti.fawe.bukkit.v1_14.BukkitQueue_1_14;
import com.boydti.fawe.bukkit.v1_14.adapter.Spigot_v1_14_R1;
import com.boydti.fawe.jnbt.anvil.BitArray4096;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes;
import net.minecraft.server.v1_14_R1.BiomeBase;
import net.minecraft.server.v1_14_R1.Chunk;
import net.minecraft.server.v1_14_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_14_R1.ChunkProviderServer;
import net.minecraft.server.v1_14_R1.ChunkSection;
import net.minecraft.server.v1_14_R1.DataBits;
import net.minecraft.server.v1_14_R1.DataPalette;
import net.minecraft.server.v1_14_R1.DataPaletteBlock;
import net.minecraft.server.v1_14_R1.DataPaletteHash;
import net.minecraft.server.v1_14_R1.DataPaletteLinear;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.World;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
import java.util.Arrays;
public class BukkitGetBlocks extends CharGetBlocks {
public ChunkSection[] sections;
public Chunk nmsChunk;
public World nmsWorld;
public int X, Z;
private boolean forceLoad;
public BukkitGetBlocks(World nmsWorld, int X, int Z, boolean forceLoad) {
this.nmsWorld = nmsWorld;
this.X = X;
this.Z = Z;
if (forceLoad) {
((WorldServer) nmsWorld).setForceLoaded(X, Z, this.forceLoad = true);
}
}
@Override
protected void finalize() {
if (forceLoad) {
((WorldServer) nmsWorld).setForceLoaded(X, Z, forceLoad = false);
}
}
@Override
public BiomeType getBiomeType(int x, int z) {
BiomeBase base = getChunk().getBiomeIndex()[(z << 4) + x];
return BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(base));
}
@Override
public CompoundTag getTag(int x, int y, int z) {
// TODO
return null;
}
@Override
public char[] load(int layer) {
return load(layer, null);
}
@Override
public synchronized char[] load(int layer, char[] data) {
ChunkSection section = getSections()[layer];
// Section is null, return empty array
if (section == null) {
return FaweCache.EMPTY_CHAR_4096;
}
if (data == null || data == FaweCache.EMPTY_CHAR_4096) {
data = new char[4096];
}
DelegateLock lock = BukkitQueue.applyLock(section);
synchronized (lock) {
lock.untilFree();
lock.setModified(false);
// Efficiently convert ChunkSection to raw data
try {
final DataPaletteBlock<IBlockData> blocks = section.getBlocks();
final DataBits bits = (DataBits) BukkitQueue_1_14.fieldBits.get(blocks);
final DataPalette<IBlockData> palette = (DataPalette<IBlockData>) BukkitQueue_1_14.fieldPalette.get(blocks);
final int bitsPerEntry = bits.c();
final long[] blockStates = bits.a();
new BitArray4096(blockStates, bitsPerEntry).toRaw(data);
int num_palette;
if (palette instanceof DataPaletteLinear) {
num_palette = ((DataPaletteLinear<IBlockData>) palette).b();
} else if (palette instanceof DataPaletteHash) {
num_palette = ((DataPaletteHash<IBlockData>) palette).b();
} else {
num_palette = 0;
int[] paletteToBlockInts = FaweCache.PALETTE_TO_BLOCK.get();
char[] paletteToBlockChars = FaweCache.PALETTE_TO_BLOCK_CHAR.get();
try {
for (int i = 0; i < 4096; i++) {
char paletteVal = data[i];
char ordinal = paletteToBlockChars[paletteVal];
if (ordinal == Character.MAX_VALUE) {
paletteToBlockInts[num_palette++] = paletteVal;
IBlockData ibd = palette.a(data[i]);
if (ibd == null) {
ordinal = BlockTypes.AIR.getDefaultState().getOrdinalChar();
} else {
ordinal = ((Spigot_v1_14_R1) getAdapter()).adaptToChar(ibd);
}
paletteToBlockChars[paletteVal] = ordinal;
}
data[i] = ordinal;
}
} finally {
for (int i = 0; i < num_palette; i++) {
int paletteVal = paletteToBlockInts[i];
paletteToBlockChars[paletteVal] = Character.MAX_VALUE;
}
}
return data;
}
char[] paletteToBlockChars = FaweCache.PALETTE_TO_BLOCK_CHAR.get();
try {
final int size = num_palette;
if (size != 1) {
for (int i = 0; i < size; i++) {
char ordinal = ordinal(palette.a(i));
paletteToBlockChars[i] = ordinal;
}
for (int i = 0; i < 4096; i++) {
char paletteVal = data[i];
char val = paletteToBlockChars[paletteVal];
data[i] = val;
}
} else {
char ordinal = ordinal(palette.a(0));
Arrays.fill(data, ordinal);
}
} finally {
for (int i = 0; i < num_palette; i++) {
paletteToBlockChars[i] = Character.MAX_VALUE;
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return data;
}
}
private final char ordinal(IBlockData ibd) {
if (ibd == null) {
return BlockTypes.AIR.getDefaultState().getOrdinalChar();
} else {
return ((Spigot_v1_14_R1) getAdapter()).adaptToChar(ibd);
}
}
public ChunkSection[] getSections() {
ChunkSection[] tmp = sections;
if (tmp == null) {
synchronized (this) {
tmp = sections;
if (tmp == null) {
Chunk chunk = getChunk();
sections = tmp = chunk.getSections().clone();
}
}
}
return tmp;
}
public Chunk getChunk() {
Chunk tmp = nmsChunk;
if (tmp == null) {
synchronized (this) {
tmp = nmsChunk;
if (tmp == null) {
nmsChunk = tmp = BukkitQueue.ensureLoaded(nmsWorld, X, Z);
}
}
}
return tmp;
}
@Override
public boolean hasSection(int layer) {
return getSections()[layer] != null;
}
@Override
public boolean trim(boolean aggressive) {
if (aggressive) {
sections = null;
nmsChunk = null;
}
return super.trim(aggressive);
}
}

Datei anzeigen

@ -0,0 +1,369 @@
package com.boydti.fawe.bukkit.beta;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.implementation.SimpleCharQueueExtent;
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.bukkit.adapter.v1_13_1.BlockMaterial_1_13;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.jnbt.anvil.BitArray4096;
import com.boydti.fawe.object.collection.IterableThreadLocal;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import net.jpountz.util.UnsafeUtils;
import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.Chunk;
import net.minecraft.server.v1_14_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_14_R1.ChunkProviderServer;
import net.minecraft.server.v1_14_R1.ChunkSection;
import net.minecraft.server.v1_14_R1.ChunkStatus;
import net.minecraft.server.v1_14_R1.DataBits;
import net.minecraft.server.v1_14_R1.DataPalette;
import net.minecraft.server.v1_14_R1.DataPaletteBlock;
import net.minecraft.server.v1_14_R1.DataPaletteLinear;
import net.minecraft.server.v1_14_R1.GameProfileSerializer;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.PlayerChunk;
import net.minecraft.server.v1_14_R1.PlayerChunkMap;
import net.minecraft.server.v1_14_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_14_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Supplier;
import sun.misc.Unsafe;
import static com.google.common.base.Preconditions.checkNotNull;
public class BukkitQueue extends SimpleCharQueueExtent {
private org.bukkit.World bukkitWorld;
private WorldServer nmsWorld;
@Override
public synchronized void init(WorldChunkCache cache) {
World world = cache.getWorld();
if (world instanceof BukkitWorld) {
this.bukkitWorld = ((BukkitWorld) world).getWorld();
} else {
this.bukkitWorld = Bukkit.getWorld(world.getName());
}
checkNotNull(this.bukkitWorld);
CraftWorld craftWorld = ((CraftWorld) bukkitWorld);
this.nmsWorld = craftWorld.getHandle();
super.init(cache);
}
public WorldServer getNmsWorld() {
return nmsWorld;
}
public org.bukkit.World getBukkitWorld() {
return bukkitWorld;
}
@Override
protected synchronized void reset() {
super.reset();
}
// private static final IterableThreadLocal<BukkitFullChunk> FULL_CHUNKS = new IterableThreadLocal<BukkitFullChunk>() {
// @Override
// public BukkitFullChunk init() {
// return new BukkitFullChunk();
// }
// };
@Override
public IChunk create(boolean full) {
// if (full) {
// //TODO implement
// return FULL_CHUNKS.get();
// }
return new BukkitChunkHolder();
}
/*
NMS fields
*/
public final static Field fieldBits;
public final static Field fieldPalette;
public final static Field fieldSize;
public final static Field fieldFluidCount;
public final static Field fieldTickingBlockCount;
public final static Field fieldNonEmptyBlockCount;
private final static Field fieldDirtyCount;
private final static Field fieldDirtyBits;
private static final int CHUNKSECTION_BASE;
private static final int CHUNKSECTION_SHIFT;
private static final Field fieldLock;
static {
try {
fieldSize = DataPaletteBlock.class.getDeclaredField("i");
fieldSize.setAccessible(true);
fieldBits = DataPaletteBlock.class.getDeclaredField("a");
fieldBits.setAccessible(true);
fieldPalette = DataPaletteBlock.class.getDeclaredField("h");
fieldPalette.setAccessible(true);
fieldFluidCount = ChunkSection.class.getDeclaredField("e");
fieldFluidCount.setAccessible(true);
fieldTickingBlockCount = ChunkSection.class.getDeclaredField("tickingBlockCount");
fieldTickingBlockCount.setAccessible(true);
fieldNonEmptyBlockCount = ChunkSection.class.getDeclaredField("nonEmptyBlockCount");
fieldNonEmptyBlockCount.setAccessible(true);
fieldDirtyCount = PlayerChunk.class.getDeclaredField("dirtyCount");
fieldDirtyCount.setAccessible(true);
fieldDirtyBits = PlayerChunk.class.getDeclaredField("h");
fieldDirtyBits.setAccessible(true);
{
Field tmp = null;
try {
tmp = DataPaletteBlock.class.getDeclaredField("j");
} catch (NoSuchFieldException paper) {
tmp = DataPaletteBlock.class.getDeclaredField("writeLock");
}
fieldLock = tmp;
fieldLock.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
int modifiers = modifiersField.getInt(fieldLock);
int newModifiers = modifiers & (~Modifier.FINAL);
if (newModifiers != modifiers) modifiersField.setInt(fieldLock, newModifiers);
}
Unsafe unsafe = UnsafeUtils.getUNSAFE();
CHUNKSECTION_BASE = unsafe.arrayBaseOffset(ChunkSection[].class);
int scale = unsafe.arrayIndexScale(ChunkSection[].class);
if ((scale & (scale - 1)) != 0)
throw new Error("data type scale not a power of two");
CHUNKSECTION_SHIFT = 31 - Integer.numberOfLeadingZeros(scale);
} catch (RuntimeException e) {
throw e;
} catch (Throwable rethrow) {
rethrow.printStackTrace();
throw new RuntimeException(rethrow);
}
}
protected static boolean setSectionAtomic(ChunkSection[] sections, ChunkSection expected, ChunkSection value, int layer) {
long offset = ((long) layer << CHUNKSECTION_SHIFT) + CHUNKSECTION_BASE;
if (layer >= 0 && layer < sections.length) {
return UnsafeUtils.getUNSAFE().compareAndSwapObject(sections, offset, expected, value);
}
return false;
}
protected static DelegateLock applyLock(ChunkSection section) {
try {
synchronized (section) {
DataPaletteBlock<IBlockData> blocks = section.getBlocks();
Lock currentLock = (Lock) fieldLock.get(blocks);
if (currentLock instanceof DelegateLock) {
return (DelegateLock) currentLock;
}
DelegateLock newLock = new DelegateLock(currentLock);
fieldLock.set(blocks, newLock);
return newLock;
}
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
private static boolean PAPER = true;
public Chunk ensureLoaded(int X, int Z) {
return ensureLoaded(nmsWorld, X, Z);
}
public static Chunk ensureLoaded(net.minecraft.server.v1_14_R1.World nmsWorld, int X, int Z) {
ChunkProviderServer provider = (ChunkProviderServer) nmsWorld.getChunkProvider();
Chunk nmsChunk = (Chunk) provider.getChunkAt(X, Z, ChunkStatus.FEATURES, false);;
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
return nmsWorld.getChunkAt(X, Z);
}
if (PAPER) {
CraftWorld craftWorld = nmsWorld.getWorld();
CompletableFuture<org.bukkit.Chunk> future = craftWorld.getChunkAtAsync(X, Z, true);
try {
CraftChunk chunk = (CraftChunk) future.get();
return chunk.getHandle();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (Throwable e) {
System.out.println("Error, cannot load chunk async (paper not installed?)");
PAPER = false;
}
}
// TODO optimize
return TaskManager.IMP.sync(() -> nmsWorld.getChunkAt(X, Z));
}
private PlayerChunk getPlayerChunk(final int cx, final int cz) {
final PlayerChunkMap chunkMap = nmsWorld.getPlayerChunkMap();
final PlayerChunk playerChunk = chunkMap.getChunk(cx, cz);
if (playerChunk == null) {
return null;
}
if (playerChunk.players.isEmpty()) {
return null;
}
return playerChunk;
}
public boolean sendChunk(final int X, final int Z, final int mask) {
PlayerChunk playerChunk = getPlayerChunk(X, Z);
if (playerChunk == null) {
return false;
}
if (playerChunk.e()) {
TaskManager.IMP.sync(new Supplier<Object>() {
@Override
public Object get() {
try {
int dirtyBits = fieldDirtyBits.getInt(playerChunk);
if (dirtyBits == 0) {
nmsWorld.getPlayerChunkMap().a(playerChunk);
}
if (mask == 0) {
dirtyBits = 65535;
} else {
dirtyBits |= mask;
}
fieldDirtyBits.set(playerChunk, dirtyBits);
fieldDirtyCount.set(playerChunk, 64);
} catch (final IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
});
}
return true;
}
/*
NMS conversion
*/
public static ChunkSection newChunkSection(final int layer, final char[] blocks) {
ChunkSection section = new ChunkSection(layer << 4);
if (blocks == null) {
return section;
}
final int[] blockToPalette = FaweCache.BLOCK_TO_PALETTE.get();
final int[] paletteToBlock = FaweCache.PALETTE_TO_BLOCK.get();
final long[] blockstates = FaweCache.BLOCK_STATES.get();
final int[] blocksCopy = FaweCache.SECTION_BLOCKS.get();
try {
int num_palette = 0;
int air = 0;
for (int i = 0; i < 4096; i++) {
char ordinal = blocks[i];
switch (ordinal) {
case 0:
case BlockID.AIR:
case BlockID.CAVE_AIR:
case BlockID.VOID_AIR:
air++;
}
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = palette = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
blocksCopy[i] = palette;
}
// BlockStates
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
if (Settings.IMP.PROTOCOL_SUPPORT_FIX || num_palette != 1) {
bitsPerEntry = Math.max(bitsPerEntry, 4); // Protocol support breaks <4 bits per entry
} else {
bitsPerEntry = Math.max(bitsPerEntry, 1); // For some reason minecraft needs 4096 bits to store 0 entries
}
final int blockBitArrayEnd = (bitsPerEntry * 4096) >> 6;
if (num_palette == 1) {
for (int i = 0; i < blockBitArrayEnd; i++) blockstates[i] = 0;
} else {
final BitArray4096 bitArray = new BitArray4096(blockstates, bitsPerEntry);
bitArray.fromRaw(blocksCopy);
}
// set palette & data bits
final DataPaletteBlock<IBlockData> dataPaletteBlocks = section.getBlocks();
// private DataPalette<T> h;
// protected DataBits a;
final long[] bits = Arrays.copyOfRange(blockstates, 0, blockBitArrayEnd);
final DataBits nmsBits = new DataBits(bitsPerEntry, 4096, bits);
final DataPalette<IBlockData> palette;
// palette = new DataPaletteHash<>(Block.REGISTRY_ID, bitsPerEntry, dataPaletteBlocks, GameProfileSerializer::d, GameProfileSerializer::a);
palette = new DataPaletteLinear<>(Block.REGISTRY_ID, bitsPerEntry, dataPaletteBlocks, GameProfileSerializer::d);
// set palette
for (int i = 0; i < num_palette; i++) {
final int ordinal = paletteToBlock[i];
blockToPalette[ordinal] = Integer.MAX_VALUE;
final BlockState state = BlockTypes.states[ordinal];
final IBlockData ibd = ((BlockMaterial_1_13) state.getMaterial()).getState();
palette.a(ibd);
}
try {
fieldBits.set(dataPaletteBlocks, nmsBits);
fieldPalette.set(dataPaletteBlocks, palette);
fieldSize.set(dataPaletteBlocks, bitsPerEntry);
setCount(0, 4096 - air, section);
} catch (final IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
return section;
} catch (final Throwable e){
Arrays.fill(blockToPalette, Integer.MAX_VALUE);
throw e;
}
}
public static void setCount(final int tickingBlockCount, final int nonEmptyBlockCount, final ChunkSection section) throws NoSuchFieldException, IllegalAccessException {
fieldFluidCount.set(section, 0); // TODO FIXME
fieldTickingBlockCount.set(section, tickingBlockCount);
fieldNonEmptyBlockCount.set(section, nonEmptyBlockCount);
}
}

Datei anzeigen

@ -0,0 +1,11 @@
package com.boydti.fawe.bukkit.beta;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.QueueHandler;
public class BukkitQueueHandler extends QueueHandler {
@Override
public IQueueExtent create() {
return new BukkitQueue();
}
}

Datei anzeigen

@ -0,0 +1,123 @@
package com.boydti.fawe.bukkit.beta;
import org.apache.commons.lang.mutable.MutableInt;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class DelegateLock extends ReentrantLock {
private final Lock parent;
private volatile boolean modified;
private final AtomicInteger count;
public DelegateLock(Lock parent) {
this.parent = parent;
if (!(parent instanceof ReentrantLock)) {
count = new AtomicInteger();
} else {
count = null;
}
}
public boolean isModified() {
return modified;
}
public void setModified(boolean modified) {
this.modified = modified;
}
@Override
public synchronized void lock() {
modified = true;
parent.lock();
if (count != null) {
count.incrementAndGet();
}
}
@Override
public synchronized void lockInterruptibly() throws InterruptedException {
parent.lockInterruptibly();
}
@Override
public synchronized boolean tryLock() {
return parent.tryLock();
}
@Override
public synchronized boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
return parent.tryLock(timeout, unit);
}
@Override
public void unlock() {
modified = true;
parent.unlock();
if (count != null) {
if (count.getAndDecrement() <= 0) {
count.incrementAndGet();
}
}
}
public Lock getParent() {
return parent;
}
@Override
public synchronized Condition newCondition() {
return parent.newCondition();
}
@Override
public synchronized int getHoldCount() {
throw new UnsupportedOperationException();
}
@Override
public synchronized boolean isHeldByCurrentThread() {
throw new UnsupportedOperationException();
}
@Override
public synchronized boolean isLocked() {
if (parent instanceof ReentrantLock) {
return ((ReentrantLock) parent).isLocked();
}
return count.get() > 0;
}
public void untilFree() {
if (parent instanceof ReentrantLock) {
ReentrantLock rl = (ReentrantLock) parent;
if (rl.isLocked()) {
rl.lock();
rl.unlock();
}
return;
}
while (count.get() > 0);
}
@Override
public synchronized boolean hasWaiters(Condition condition) {
throw new UnsupportedOperationException();
}
@Override
public synchronized int getWaitQueueLength(Condition condition) {
throw new UnsupportedOperationException();
}
@Override
public synchronized String toString() {
return parent.toString();
}
}

Datei anzeigen

@ -220,34 +220,9 @@ public abstract class BukkitQueue_0<CHUNK, CHUNKSECTIONS, SECTION> extends NMSMa
} }
} }
public static ConcurrentHashMap<Long, Long> keepLoaded = new ConcurrentHashMap<>(8, 0.9f, 1);
@EventHandler
public static void onChunkLoad(ChunkLoadEvent event) {
Chunk chunk = event.getChunk();
long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());
keepLoaded.putIfAbsent(pair, Fawe.get().getTimer().getTickStart());
}
@EventHandler
public static void onChunkUnload(ChunkUnloadEvent event) {
Chunk chunk = event.getChunk();
long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());
Long lastLoad = keepLoaded.get(pair);
if (lastLoad != null) {
if (Fawe.get().getTimer().getTickStart() - lastLoad < 10000) {
event.setCancelled(true);
} else {
keepLoaded.remove(pair);
}
}
}
@Override @Override
public boolean queueChunkLoad(int cx, int cz) { public boolean queueChunkLoad(int cx, int cz) {
if (super.queueChunkLoad(cx, cz)) { if (super.queueChunkLoad(cx, cz)) {
keepLoaded.put(MathMan.pairInt(cx, cz), System.currentTimeMillis());
return true; return true;
} }
return false; return false;
@ -282,7 +257,6 @@ public abstract class BukkitQueue_0<CHUNK, CHUNKSECTIONS, SECTION> extends NMSMa
@Override @Override
public boolean regenerateChunk(World world, int x, int z, BiomeType biome, Long seed) { public boolean regenerateChunk(World world, int x, int z, BiomeType biome, Long seed) {
if (!keepLoaded.isEmpty()) keepLoaded.remove(MathMan.pairInt(x, z));
return world.regenerateChunk(x, z); return world.regenerateChunk(x, z);
} }

Datei anzeigen

@ -233,19 +233,11 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
ChunkSnapshot cached = chunkCache.get(pair); ChunkSnapshot cached = chunkCache.get(pair);
if (cached != null) return cached; if (cached != null) return cached;
if (world.isChunkLoaded(cx, cz)) { if (world.isChunkLoaded(cx, cz)) {
Long originalKeep = keepLoaded.get(pair);
keepLoaded.put(pair, Long.MAX_VALUE);
if (world.isChunkLoaded(cx, cz)) { if (world.isChunkLoaded(cx, cz)) {
Chunk chunk = world.getChunkAt(cx, cz); Chunk chunk = world.getChunkAt(cx, cz);
ChunkSnapshot snapshot = getAndCacheChunk(chunk); ChunkSnapshot snapshot = getAndCacheChunk(chunk);
if (originalKeep != null) {
keepLoaded.put(pair, originalKeep);
} else {
keepLoaded.remove(pair);
}
return snapshot; return snapshot;
} else { } else {
keepLoaded.remove(pair);
return null; return null;
} }
} else { } else {

Datei anzeigen

@ -40,7 +40,7 @@ import java.util.concurrent.atomic.LongAdder;
public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R2.Chunk, ChunkSection[], ChunkSection> { public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R2.Chunk, ChunkSection[], ChunkSection> {
protected final static Field fieldBits; final static Field fieldBits;
final static Field fieldPalette; final static Field fieldPalette;
final static Field fieldSize; final static Field fieldSize;
@ -604,10 +604,10 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
} }
static ChunkSection newChunkSection(int y2, boolean flag, int[] blocks) { static ChunkSection newChunkSection(int y2, boolean flag, int[] blocks) {
if (blocks == null) {
return new ChunkSection(y2 << 4, flag);
} else {
ChunkSection section = new ChunkSection(y2 << 4, flag); ChunkSection section = new ChunkSection(y2 << 4, flag);
if (blocks == null) {
return section;
}
int[] blockToPalette = FaweCache.BLOCK_TO_PALETTE.get(); int[] blockToPalette = FaweCache.BLOCK_TO_PALETTE.get();
int[] paletteToBlock = FaweCache.PALETTE_TO_BLOCK.get(); int[] paletteToBlock = FaweCache.PALETTE_TO_BLOCK.get();
long[] blockstates = FaweCache.BLOCK_STATES.get(); long[] blockstates = FaweCache.BLOCK_STATES.get();
@ -682,7 +682,6 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
throw e; throw e;
} }
} }
}
protected BlockPosition.MutableBlockPosition pos = new BlockPosition.MutableBlockPosition(0, 0, 0); protected BlockPosition.MutableBlockPosition pos = new BlockPosition.MutableBlockPosition(0, 0, 0);

Datei anzeigen

@ -20,6 +20,7 @@
package com.boydti.fawe.bukkit.v1_14.adapter; package com.boydti.fawe.bukkit.v1_14.adapter;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.bukkit.adapter.v1_13_1.BlockMaterial_1_13;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.ByteArrayTag;
@ -149,16 +150,16 @@ public final class Spigot_v1_14_R1 extends CachedBukkitAdapter implements Bukkit
nbtCreateTagMethod.setAccessible(true); nbtCreateTagMethod.setAccessible(true);
} }
public int[] idbToStateOrdinal; public char[] idbToStateOrdinal;
private boolean init() { private synchronized boolean init() {
if (idbToStateOrdinal != null) return false; if (idbToStateOrdinal != null) return false;
idbToStateOrdinal = new int[Block.REGISTRY_ID.a()]; // size idbToStateOrdinal = new char[Block.REGISTRY_ID.a()]; // size
for (int i = 0; i < idbToStateOrdinal.length; i++) { for (int i = 0; i < idbToStateOrdinal.length; i++) {
BlockState state = BlockTypes.states[i]; BlockState state = BlockTypes.states[i];
BlockMaterial_1_14 material = (BlockMaterial_1_14) state.getMaterial(); BlockMaterial_1_14 material = (BlockMaterial_1_14) state.getMaterial();
int id = Block.REGISTRY_ID.getId(material.getState()); int id = Block.REGISTRY_ID.getId(material.getState());
idbToStateOrdinal[id] = state.getOrdinal(); idbToStateOrdinal[id] = state.getOrdinalChar();
} }
return true; return true;
} }
@ -580,8 +581,18 @@ public final class Spigot_v1_14_R1 extends CachedBukkitAdapter implements Bukkit
int id = Block.REGISTRY_ID.getId(ibd); int id = Block.REGISTRY_ID.getId(ibd);
return idbToStateOrdinal[id]; return idbToStateOrdinal[id];
} catch (NullPointerException e) { } catch (NullPointerException e) {
if (init()) return adaptToInt(ibd); init();
throw e; return adaptToInt(ibd);
}
}
public char adaptToChar(IBlockData ibd) {
try {
int id = Block.REGISTRY_ID.getId(ibd);
return idbToStateOrdinal[id];
} catch (NullPointerException e) {
init();
return adaptToChar(ibd);
} }
} }

Datei anzeigen

@ -87,16 +87,8 @@ public class AsyncChunk implements Chunk {
if (queue instanceof BukkitQueue_0) { if (queue instanceof BukkitQueue_0) {
BukkitQueue_0 bq = (BukkitQueue_0) queue; BukkitQueue_0 bq = (BukkitQueue_0) queue;
if (world.isChunkLoaded(x, z)) { if (world.isChunkLoaded(x, z)) {
long pair = MathMan.pairInt(x, z);
Long originalKeep = BukkitQueue_0.keepLoaded.get(pair);
BukkitQueue_0.keepLoaded.put(pair, Long.MAX_VALUE);
if (world.isChunkLoaded(x, z)) { if (world.isChunkLoaded(x, z)) {
task.run(); task.run();
if (originalKeep != null) {
BukkitQueue_0.keepLoaded.put(pair, originalKeep);
} else {
BukkitQueue_0.keepLoaded.remove(pair);
}
return task.value; return task.value;
} }
} }

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe.bukkit.wrapper; package com.boydti.fawe.bukkit.wrapper;
import com.bekvon.bukkit.residence.commands.material;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0; import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
@ -174,11 +175,6 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue
}); });
} }
@Override
public boolean unloadChunkRequest(int x, int z) {
return unloadChunk(x, z);
}
@Override @Override
public void spawnParticle(Particle particle, Location location, int i) { public void spawnParticle(Particle particle, Location location, int i) {
parent.spawnParticle(particle, location, i); parent.spawnParticle(particle, location, i);
@ -397,6 +393,19 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue
return true; return true;
} }
@Override
public boolean unloadChunkRequest(int x, int z) {
if (isChunkLoaded(x, z)) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() {
@Override
public void run(Boolean value) {
this.value = parent.unloadChunkRequest(x, z);
}
});
}
return true;
}
@Override @Override
public boolean regenerateChunk(final int x, final int z) { public boolean regenerateChunk(final int x, final int z) {
return TaskManager.IMP.sync(new RunnableVal<Boolean>() { return TaskManager.IMP.sync(new RunnableVal<Boolean>() {

Datei anzeigen

@ -0,0 +1,114 @@
package com.boydti.fawe.bukkit.wrapper.state;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Map.Entry;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.Tag;
import net.minecraft.server.v1_14_R1.NBTBase;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import org.apache.commons.lang.Validate;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v1_14_R1.persistence.CraftPersistentDataAdapterContext;
import org.bukkit.craftbukkit.v1_14_R1.persistence.CraftPersistentDataTypeRegistry;
import org.bukkit.persistence.PersistentDataAdapterContext;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
public final class AsyncDataContainer implements PersistentDataContainer {
private final CompoundTag root;
public AsyncDataContainer(CompoundTag root) {
this.root = root;
}
private CompoundTag root() {
CompoundTag value = (CompoundTag) root.getValue().get("PublicBukkitValues");
return value;
}
private Map<String, Tag> get() {
return get(true);
}
private Map<String, Tag> get(boolean create) {
CompoundTag tag = root();
Map<String, Tag> raw;
if (tag == null) {
if (!create) return Collections.emptyMap();
Map<String, Tag> map = ReflectionUtils.getMap(root.getValue());
map.put("PublicBukkitValues", new CompoundTag(raw = new HashMap<>()));
} else {
raw = ReflectionUtils.getMap(tag.getValue());
}
return raw;
}
public <T, Z> void set(NamespacedKey key, PersistentDataType<T, Z> type, Z value) {
Validate.notNull(key, "The provided key for the custom value was null");
Validate.notNull(type, "The provided type for the custom value was null");
Validate.notNull(value, "The provided value for the custom value was null");
get().put(key.toString(), FaweCache.asTag(type.toPrimitive(value, null)));
}
public <T, Z> boolean has(NamespacedKey key, PersistentDataType<T, Z> type) {
Validate.notNull(key, "The provided key for the custom value was null");
Validate.notNull(type, "The provided type for the custom value was null");
Tag value = get(false).get(key.toString());
if (value == null) return type == null;
return type.getPrimitiveType() == value.getValue().getClass();
}
public <T, Z> Z get(NamespacedKey key, PersistentDataType<T, Z> type) {
Validate.notNull(key, "The provided key for the custom value was null");
Validate.notNull(type, "The provided type for the custom value was null");
Tag value = get(false).get(key.toString());
return (Z) value.toRaw();
}
public <T, Z> Z getOrDefault(NamespacedKey key, PersistentDataType<T, Z> type, Z defaultValue) {
Z z = this.get(key, type);
return z != null ? z : defaultValue;
}
public void remove(NamespacedKey key) {
Validate.notNull(key, "The provided key for the custom value was null");
get(false).remove(key.toString());
}
public boolean isEmpty() {
return get(false).isEmpty();
}
public PersistentDataAdapterContext getAdapterContext() {
return null;
}
public boolean equals(Object obj) {
if (!(obj instanceof AsyncDataContainer)) {
return false;
} else {
Map<String, Tag> myRawMap = this.getRaw();
Map<String, Tag> theirRawMap = ((AsyncDataContainer)obj).getRaw();
return Objects.equals(myRawMap, theirRawMap);
}
}
public Map<String, Tag> getRaw() {
return get(false);
}
public int hashCode() {
return get(false).hashCode();
}
public Map<String, Object> serialize() {
return new CompoundTag(get(false)).toRaw();
}
}

Datei anzeigen

@ -8,7 +8,13 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import java.util.Map; import java.util.Map;
import net.minecraft.server.v1_14_R1.TileEntitySign;
import org.bukkit.DyeColor;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.persistence.PersistentDataContainer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class AsyncSign extends AsyncBlockState implements Sign { public class AsyncSign extends AsyncBlockState implements Sign {
public AsyncSign(AsyncBlock block, int combined) { public AsyncSign(AsyncBlock block, int combined) {
@ -63,4 +69,28 @@ public class AsyncSign extends AsyncBlockState implements Sign {
public void setEditable(boolean arg0) { public void setEditable(boolean arg0) {
this.isEditable = arg0; this.isEditable = arg0;
} }
@Override
public @NotNull PersistentDataContainer getPersistentDataContainer() {
return new AsyncDataContainer(getNbtData());
}
@Override
public @Nullable DyeColor getColor() {
CompoundTag nbt = getNbtData();
if (nbt != null) {
String color = nbt.getString("Color").toUpperCase();
if (color != null) return DyeColor.valueOf(color);
}
return DyeColor.BLACK;
}
@Override
public void setColor(DyeColor color) {
CompoundTag nbt = getNbtData();
if (nbt != null) {
Map<String, Tag> map = ReflectionUtils.getMap(nbt.getValue());
map.put("Color", new StringTag(color.name().toLowerCase()));
}
}
} }

Datei anzeigen

@ -438,11 +438,6 @@ public class BukkitWorld extends AbstractWorld {
} }
} }
@Override
public com.sk89q.worldedit.world.block.BlockState getLazyBlock(BlockVector3 position) {
return getBlock(position);
}
@Override @Override
public BaseBlock getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();

Datei anzeigen

@ -23,7 +23,7 @@ import com.bekvon.bukkit.residence.commands.message;
import com.bekvon.bukkit.residence.containers.cmd; import com.bekvon.bukkit.residence.containers.cmd;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.bukkit.FaweBukkit;
import com.boydti.fawe.bukkit.adapter.v1_13_1.Spigot_v1_13_R2; import com.boydti.fawe.bukkit.v1_14.adapter.Spigot_v1_14_R1;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -322,7 +322,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
// Attempt to load a Bukkit adapter // Attempt to load a Bukkit adapter
BukkitImplLoader adapterLoader = new BukkitImplLoader(); BukkitImplLoader adapterLoader = new BukkitImplLoader();
try { try {
adapterLoader.addClass(Spigot_v1_13_R2.class); adapterLoader.addClass(Spigot_v1_14_R1.class);
} catch (Throwable throwable) { } catch (Throwable throwable) {
throwable.printStackTrace(); throwable.printStackTrace();
} }

Datei anzeigen

@ -1,94 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.block.BaseBlock;
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.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
/**
* A implementation of a lazy block for {@link Extent#getLazyBlock(Vector)}
* that takes the block's ID and metadata, but will defer loading of NBT
* data until time of access.
*
* <p>NBT data is later loaded using a call to {@link Extent#getBlock(Vector)}
* with a stored {@link Extent} and location.</p>
*
* <p>All mutators on this object will throw an
* {@link UnsupportedOperationException}.</p>
*/
public class LazyBlock extends BaseBlock {
private final Extent extent;
private final BlockVector3 position;
private boolean loaded = false;
/**
* Create a new lazy block.
*
* @param type the block type
* @param extent the extent to later load the full block data from
* @param position the position to later load the full block data from
*/
public LazyBlock(BlockType type, Extent extent, BlockVector3 position) {
super(type);
checkNotNull(extent);
checkNotNull(position);
this.extent = extent;
this.position = position;
}
/**
* Create a new lazy block.
*
* @param state the block state
* @param extent the extent to later load the full block data from
* @param position the position to later load the full block data from
*/
public LazyBlock(BlockState state, Extent extent, BlockVector3 position) {
super(state);
checkNotNull(extent);
checkNotNull(position);
this.extent = extent;
this.position = position;
}
@Override
public CompoundTag getNbtData() {
if (!loaded) {
BaseBlock loadedBlock = extent.getFullBlock(position);
this.nbtData = loadedBlock.getNbtData();
loaded = true;
}
return super.getNbtData();
}
@Override
public void setNbtData(CompoundTag nbtData) {
throw new UnsupportedOperationException("This object is immutable");
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe; package com.boydti.fawe;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Commands; import com.boydti.fawe.config.Commands;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
@ -81,6 +82,8 @@ public class Fawe {
private DefaultTransformParser transformParser; private DefaultTransformParser transformParser;
private ChatManager chatManager = new PlainChatManager(); private ChatManager chatManager = new PlainChatManager();
private QueueHandler queueHandler;
/** /**
* Get the implementation specific class * Get the implementation specific class
* *
@ -183,6 +186,17 @@ public class Fawe {
public void onDisable() { public void onDisable() {
} }
public QueueHandler getQueueHandler() {
if (queueHandler == null) {
synchronized (this) {
if (queueHandler == null) {
queueHandler = IMP.getQueueHandler();
}
}
}
return queueHandler;
}
public ChatManager getChatManager() { public ChatManager getChatManager() {
return chatManager; return chatManager;
} }

Datei anzeigen

@ -8,6 +8,7 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.changeset.DiskStorageHistory; import com.boydti.fawe.object.changeset.DiskStorageHistory;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.schematic.Schematic; import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.EditSessionBuilder;
@ -262,7 +263,7 @@ public class FaweAPI {
*/ */
public static void cancelEdit(Extent extent, BBC reason) { public static void cancelEdit(Extent extent, BBC reason) {
try { try {
WEManager.IMP.cancelEdit(extent, reason); WEManager.IMP.cancelEdit(extent, new FaweException(reason));
} catch (WorldEditException ignore) { } catch (WorldEditException ignore) {
} }
} }

Datei anzeigen

@ -1,14 +1,47 @@
package com.boydti.fawe; package com.boydti.fawe;
import com.boydti.fawe.beta.Trimable;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.jnbt.anvil.BitArray4096;
import com.boydti.fawe.object.collection.IterableThreadLocal; import com.boydti.fawe.object.collection.IterableThreadLocal;
import com.boydti.fawe.util.MathMan;
import com.sk89q.jnbt.*; import com.sk89q.jnbt.*;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.MutableVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class FaweCache implements Trimable {
public static final char[] EMPTY_CHAR_4096 = new char[4096];
/*
Palette buffers / cache
*/
@Override
public boolean trim(boolean aggressive) {
BLOCK_TO_PALETTE.clean();
PALETTE_TO_BLOCK.clean();
BLOCK_STATES.clean();
SECTION_BLOCKS.clean();
PALETTE_CACHE.clean();
PALETTE_TO_BLOCK_CHAR.clean();
MUTABLE_VECTOR3.clean();
MUTABLE_BLOCKVECTOR3.clean();
return false;
}
public class FaweCache {
public static final IterableThreadLocal<int[]> BLOCK_TO_PALETTE = new IterableThreadLocal<int[]>() { public static final IterableThreadLocal<int[]> BLOCK_TO_PALETTE = new IterableThreadLocal<int[]>() {
@Override @Override
public int[] init() { public int[] init() {
@ -21,7 +54,16 @@ public class FaweCache {
public static final IterableThreadLocal<int[]> PALETTE_TO_BLOCK = new IterableThreadLocal<int[]>() { public static final IterableThreadLocal<int[]> PALETTE_TO_BLOCK = new IterableThreadLocal<int[]>() {
@Override @Override
public int[] init() { public int[] init() {
return new int[Character.MAX_VALUE]; return new int[Character.MAX_VALUE + 1];
}
};
public static final IterableThreadLocal<char[]> PALETTE_TO_BLOCK_CHAR = new IterableThreadLocal<char[]>() {
@Override
public char[] init() {
char[] result = new char[Character.MAX_VALUE + 1];
Arrays.fill(result, Character.MAX_VALUE);
return result;
} }
}; };
@ -39,6 +81,141 @@ public class FaweCache {
} }
}; };
/**
* Holds data for a palette used in a chunk section
*/
public static final class Palette {
public int paletteToBlockLength;
/**
* Reusable buffer array, MUST check paletteToBlockLength for actual length
*/
public int[] paletteToBlock;
public int blockstatesLength;
/**
* Reusable buffer array, MUST check blockstatesLength for actual length
*/
public long[] blockstates;
}
private static final IterableThreadLocal<Palette> PALETTE_CACHE = new IterableThreadLocal<Palette>() {
@Override
public Palette init() {
return new Palette();
}
};
/**
* Convert raw char array to palette
* @param layerOffset
* @param blocks
* @return palette
*/
public static Palette toPalette(int layerOffset, char[] blocks) {
return toPalette(layerOffset, null, blocks);
}
/**
* Convert raw int array to palette
* @param layerOffset
* @param blocks
* @return palette
*/
public static Palette toPalette(int layerOffset, int[] blocks) {
return toPalette(layerOffset, blocks, null);
}
private static Palette toPalette(int layerOffset, int[] blocksInts, char[] blocksChars) {
int[] blockToPalette = BLOCK_TO_PALETTE.get();
int[] paletteToBlock = PALETTE_TO_BLOCK.get();
long[] blockstates = BLOCK_STATES.get();
int[] blocksCopy = SECTION_BLOCKS.get();
int blockIndexStart = layerOffset << 12;
int blockIndexEnd = blockIndexStart + 4096;
int num_palette = 0;
try {
if (blocksChars != null) {
for (int i = blockIndexStart, j = 0; i < blockIndexEnd; i++, j++) {
int ordinal = blocksChars[i];
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
// BlockState state = BlockTypes.states[ordinal];
blockToPalette[ordinal] = palette = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
blocksCopy[j] = palette;
}
} else if (blocksInts != null) {
for (int i = blockIndexStart, j = 0; i < blockIndexEnd; i++, j++) {
int ordinal = blocksInts[i];
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
BlockState state = BlockTypes.states[ordinal];
blockToPalette[ordinal] = palette = num_palette;
paletteToBlock[num_palette] = ordinal;
num_palette++;
}
blocksCopy[j] = palette;
}
} else {
throw new IllegalArgumentException();
}
for (int i = 0; i < num_palette; i++) {
blockToPalette[paletteToBlock[i]] = Integer.MAX_VALUE;
}
// BlockStates
int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
int blockBitArrayEnd = (bitsPerEntry * 4096) >> 6;
if (num_palette == 1) {
// Set a value, because minecraft needs it for some reason
blockstates[0] = 0;
blockBitArrayEnd = 1;
} else {
BitArray4096 bitArray = new BitArray4096(blockstates, bitsPerEntry);
bitArray.fromRaw(blocksCopy);
}
// Construct palette
Palette palette = PALETTE_CACHE.get();
palette.paletteToBlockLength = num_palette;
palette.paletteToBlock = paletteToBlock;
palette.blockstatesLength = blockBitArrayEnd;
palette.blockstates = blockstates;
return palette;
} catch (Throwable e) {
Arrays.fill(blockToPalette, Integer.MAX_VALUE);
e.printStackTrace();
throw e;
}
}
/*
* Vector cache
*/
public static IterableThreadLocal<MutableBlockVector3> MUTABLE_BLOCKVECTOR3 = new IterableThreadLocal<MutableBlockVector3>() {
@Override
public MutableBlockVector3 init() {
return new MutableBlockVector3();
}
};
public static IterableThreadLocal<MutableVector3> MUTABLE_VECTOR3 = new IterableThreadLocal<MutableVector3>() {
@Override
public MutableVector3 init() {
return new MutableVector3();
}
};
/*
Conversion methods between JNBT tags and raw values
*/
public static Map<String, Object> asMap(Object... pairs) { public static Map<String, Object> asMap(Object... pairs) {
HashMap<String, Object> map = new HashMap<>(pairs.length >> 1); HashMap<String, Object> map = new HashMap<>(pairs.length >> 1);
for (int i = 0; i < pairs.length; i += 2) { for (int i = 0; i < pairs.length; i += 2) {
@ -179,4 +356,16 @@ public class FaweCache {
if (clazz == null) clazz = EndTag.class; if (clazz == null) clazz = EndTag.class;
return new ListTag(clazz, list); return new ListTag(clazz, list);
} }
/*
Thread stuff
*/
public static ThreadPoolExecutor newBlockingExecutor() {
int nThreads = Settings.IMP.QUEUE.PARALLEL_THREADS;
ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(nThreads);
return new ThreadPoolExecutor(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS, queue
, Executors.defaultThreadFactory(),
new ThreadPoolExecutor.CallerRunsPolicy());
}
} }

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe; package com.boydti.fawe;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FaweCommand;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
@ -57,4 +58,6 @@ public interface IFawe {
return ""; return "";
} }
QueueHandler getQueueHandler();
} }

Datei anzeigen

@ -0,0 +1,89 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
public class ArrayFilterBlock extends SimpleFilterBlock {
private final char[] blocks;
private final byte[] heights;
private final int yOffset;
private int x, z, index;
private char ordinal;
private final int width, length;
public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length, int yOffset) {
super(extent);
this.blocks = blocks;
this.width = width;
this.length = length;
this.heights = heights;
this.yOffset = yOffset;
}
public void filter2D(Filter filter) {
for (z = 0; z < length; z++) {
for (x = 0; x < width; x++, index++) {
ordinal = blocks[ordinal];
filter.applyBlock(this);
}
}
}
@Override
public void setOrdinal(int ordinal) {
blocks[index] = (char) ordinal;
}
@Override
public void setBlock(BlockState state) {
blocks[index] = state.getOrdinalChar();
}
@Override
public void setFullBlock(BaseBlock block) {
blocks[index] = block.getOrdinalChar();
}
@Override
public int getOrdinal() {
return ordinal;
}
@Override
public BlockState getBlock() {
return BlockTypes.states[ordinal];
}
@Override
public BaseBlock getFullBlock() {
return getBlock().toBaseBlock();
}
@Override
public CompoundTag getNbtData() {
return null;
}
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {}
@Override
public int getX() {
return x;
}
@Override
public int getY() {
return (heights[index] & 0xFF) + yOffset;
}
@Override
public int getZ() {
return z;
}
}

Datei anzeigen

@ -0,0 +1,418 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import javax.annotation.Nullable;
import static com.sk89q.worldedit.world.block.BlockTypes.states;
public class CharFilterBlock extends ChunkFilterBlock {
private CharGetBlocks get;
private IChunkSet set;
private char[] getArr;
private @Nullable char[] setArr;
private SetDelegate delegate;
// local
private int layer, index, x, y, z, xx, yy, zz, X, Z;
public CharFilterBlock(IQueueExtent queueExtent) {
super(queueExtent);
}
@Override
public final ChunkFilterBlock init(final int X, final int Z, final IChunkGet chunk) {
this.get = (CharGetBlocks) chunk;
this.X = X;
this.Z = Z;
this.xx = X << 4;
this.zz = Z << 4;
return this;
}
public void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask) {
final int maxDepth = flood.getMaxDepth();
final boolean checkDepth = maxDepth < Character.MAX_VALUE;
if (init(iget, iset, layer) != null) {
while ((index = flood.poll()) != -1) {
x = index & 15;
z = (index >> 4) & 15;
y = (index >> 8) & 15;
if (mask.applyBlock(this)) {
int depth = index >> 12;
if (checkDepth && depth > maxDepth) {
continue;
}
flood.apply(x, y, z, depth);
}
}
}
}
@Override
public final ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer) {
this.layer = layer;
final CharGetBlocks get = (CharGetBlocks) iget;
if (!get.hasSection(layer)) return null;
this.set = iset;
getArr = get.sections[layer].get(get, layer);
if (set.hasSection(layer)) {
setArr = set.getArray(layer);
delegate = FULL;
} else {
delegate = NULL;
setArr = null;
}
this.yy = layer << 4;
return this;
}
@Override
public void filter(Filter filter, int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
this.index = x | (z << 4) | (y << 8);
filter.applyBlock(this);
}
@Override
public void filter(Filter filter, int yStart, int yEnd) {
for (y = yStart, index = (yStart << 8); y < yEnd; y++) {
for (z = 0; z < 16; z++) {
for (x = 0; x < 16; x++, index++) {
filter.applyBlock(this);
}
}
}
}
@Override
public void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
int yis = (minY << 8);
int zis = (minZ << 4);
for (y = minY, index = yis; y <= maxY; y++) {
for (z = minZ, index += zis; z <= maxZ; z++) {
for (x = minX, index += minX; x <= maxX; x++, index++) {
filter.applyBlock(this);
}
}
}
}
@Override
public final void filter(final Filter filter, final Region region) {
for (y = 0, index = 0; y < 16; y++) {
int absY = yy + y;
for (z = 0; z < 16; z++) {
int absZ = zz + z;
for (x = 0; x < 16; x++, index++) {
int absX = xx + x;
if (region.contains(absX, absY, absZ)) {
filter.applyBlock(this);
}
}
}
}
}
@Override
public final void filter(final Filter filter) {
for (y = 0, index = 0; y < 16; y++) {
for (z = 0; z < 16; z++) {
for (x = 0; x < 16; x++, index++) {
filter.applyBlock(this);
}
}
}
}
@Override
public void setBiome(BiomeType biome) {
set.setBiome(x, y, z, biome);
}
@Override
public void setOrdinal(final int ordinal) {
delegate.set(this, (char) ordinal);
}
@Override
public void setBlock(final BlockState state) {
delegate.set(this, state.getOrdinalChar());
}
@Override
public void setFullBlock(final BaseBlock block) {
delegate.set(this, block.getOrdinalChar());
final CompoundTag nbt = block.getNbtData();
if (nbt != null) { // TODO optimize check via ImmutableBaseBlock
set.setTile(x, yy + y, z, nbt);
}
}
@Override
public final int getX() {
return xx + x;
}
@Override
public final int getY() {
return yy + y;
}
@Override
public final int getZ() {
return zz + z;
}
@Override
public final int getLocalX() {
return x;
}
@Override
public final int getLocalY() {
return y;
}
@Override
public final int getLocalZ() {
return z;
}
@Override
public final int getChunkX() {
return X;
}
@Override
public final int getChunkZ() {
return Z;
}
public final char getOrdinalChar() {
return getArr[index];
}
@Override
public final int getOrdinal() {
return getArr[index];
}
@Override
public final BlockState getBlock() {
final int ordinal = getArr[index];
return BlockTypes.states[ordinal];
}
@Override
public final BaseBlock getFullBlock() {
final BlockState state = getBlock();
final BlockMaterial material = state.getMaterial();
if (material.hasContainer()) {
final CompoundTag tag = get.getTag(x, y + yy, z);
return state.toBaseBlock(tag);
}
return state.toBaseBlock();
}
@Override
public final CompoundTag getNbtData() {
return get.getTag(x, y + (layer << 4), z);
}
@Override
public void setNbtData(CompoundTag tag) {
if (tag != null) {
set.setTile(x, y + yy, z, tag);
}
}
@Override
public boolean hasNbtData() {
final BlockState state = getBlock();
final BlockMaterial material = state.getMaterial();
return material.hasContainer();
}
/*
NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1),
EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2),
SOUTH(Vector3.at(0, 0, 1), Flag.CARDINAL, 1, 3),
WEST(Vector3.at(-1, 0, 0), Flag.CARDINAL, 2, 0),
*/
@Override
public final BlockState getBlockNorth() {
if (z > 0) {
return states[getArr[index - 16]];
}
return getExtent().getBlock(getX(), getY(), getZ() - 1);
}
@Override
public final BlockState getBlockEast() {
if (x < 15) {
return states[getArr[index + 1]];
}
return getExtent().getBlock(getX() + 1, getY(), getZ());
}
@Override
public final BlockState getBlockSouth() {
if (z < 15) {
return states[getArr[index + 16]];
}
return getExtent().getBlock(getX(), getY(), getZ() + 1);
}
@Override
public final BlockState getBlockWest() {
if (x > 0) {
return states[getArr[index - 1]];
}
return getExtent().getBlock(getX() - 1, getY(), getZ());
}
@Override
public final BlockState getBlockBelow() {
if (y > 0) {
return states[getArr[index - 256]];
}
if (layer > 0) {
final int newLayer = layer - 1;
final CharGetBlocks chunk = this.get;
return states[chunk.sections[newLayer].get(chunk, newLayer, index + 3840)];
}
return BlockTypes.__RESERVED__.getDefaultState();
}
@Override
public final BlockState getBlockAbove() {
if (y < 16) {
return states[getArr[index + 256]];
}
if (layer < 16) {
final int newLayer = layer + 1;
final CharGetBlocks chunk = this.get;
return states[chunk.sections[newLayer].get(chunk, newLayer, index - 3840)];
}
return BlockTypes.__RESERVED__.getDefaultState();
}
@Override
public final BlockState getBlockRelativeY(final int y) {
final int newY = this.y + y;
final int layerAdd = newY >> 4;
switch (layerAdd) {
case 0:
return states[getArr[this.index + (y << 8)]];
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15: {
final int newLayer = layer + layerAdd;
if (newLayer < 16) {
final int index = this.index + ((y & 15) << 8);
return states[get.sections[newLayer].get(get, newLayer, index)];
}
break;
}
case -1:
case -2:
case -3:
case -4:
case -5:
case -6:
case -7:
case -8:
case -9:
case -10:
case -11:
case -12:
case -13:
case -14:
case -15: {
final int newLayer = layer + layerAdd;
if (newLayer >= 0) {
final int index = this.index + ((y & 15) << 8);
return states[get.sections[newLayer].get(get, newLayer, index)];
}
break;
}
}
return BlockTypes.__RESERVED__.getDefaultState();
}
/*
Extent
*/
@Override
public char getOrdinalChar(Extent orDefault) {
return getOrdinalChar();
}
/*
Set delegate
*/
private SetDelegate initSet() {
setArr = set.getArray(layer);
return delegate = FULL;
}
@Override
public BiomeType getBiomeType(int x, int z) {
if ((x >> 4) == X && (z >> 4) == Z) {
return get.getBiomeType(x & 15, z & 15);
}
return getExtent().getBiomeType(x, z);
}
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
if ((x >> 4) == X && (z >> 4) == Z) {
return set.setBiome(x & 15, y, z & 15, biome);
}
return getExtent().setBiome(x, y, z, biome);
}
private interface SetDelegate {
void set(CharFilterBlock block, char value);
}
private static final SetDelegate NULL = new SetDelegate() {
@Override
public void set(final CharFilterBlock block, final char value) {
block.initSet().set(block, value);
}
};
private static final SetDelegate FULL = new SetDelegate() {
@Override
public final void set(final CharFilterBlock block, final char value) {
block.setArr[block.index] = value;
}
};
}

Datei anzeigen

@ -0,0 +1,30 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable;
public abstract class ChunkFilterBlock extends SimpleFilterBlock {
public ChunkFilterBlock(Extent extent) {
super(extent);
}
public abstract ChunkFilterBlock init(int X, int Z, IChunkGet chunk);
public abstract ChunkFilterBlock init(final IChunkGet iget, final IChunkSet iset, final int layer);
public abstract void flood(final IChunkGet iget, final IChunkSet iset, final int layer, Flood flood, FilterBlockMask mask);
public abstract void filter(Filter filter, int x, int y, int z);
public abstract void filter(Filter filter, int minX, int minY, int minZ, int maxX, int maxY, int maxZ);
public abstract void filter(Filter filter);
public abstract void filter(Filter filter, int yStart, int yEnd);
public abstract void filter(final Filter filter, final Region region);
}

Datei anzeigen

@ -0,0 +1,60 @@
package com.boydti.fawe.beta;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class ChunkFuture implements Future<Void> {
private final IChunk chunk;
private volatile boolean cancelled;
private volatile boolean done;
public ChunkFuture(final IChunk chunk) {
this.chunk = chunk;
}
public IChunk getChunk() {
return chunk;
}
@Override
public boolean cancel(final boolean mayInterruptIfRunning) {
cancelled = true;
if (done) return false;
return true;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public boolean isDone() {
return done;
}
@Override
public Void get() throws InterruptedException, ExecutionException {
synchronized (chunk) {
if (!done) {
this.wait();
}
}
return null;
}
@Override
public Void get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
synchronized (chunk) {
if (!done) {
this.wait(unit.toMillis(timeout));
if (!done) {
throw new TimeoutException();
}
}
}
return null;
}
}

Datei anzeigen

@ -0,0 +1,13 @@
package com.boydti.fawe.beta;
public abstract class DelegateFilter implements IDelegateFilter {
private final Filter parent;
public DelegateFilter(Filter parent) {
this.parent = parent;
}
@Override
public Filter getParent() {
return parent;
}
}

Datei anzeigen

@ -0,0 +1,697 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.jnbt.anvil.generator.GenBase;
import com.boydti.fawe.jnbt.anvil.generator.Resource;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.List;
public class DelegateFilterBlock extends FilterBlock {
private final FilterBlock parent;
public DelegateFilterBlock(FilterBlock parent) {
this.parent = parent;
}
@Override
public Extent getExtent() {
return parent.getExtent();
}
@Override
public void setOrdinal(int ordinal) {
parent.setOrdinal(ordinal);
}
@Override
public void setBlock(BlockState state) {
parent.setBlock(state);
}
@Override
public void setFullBlock(BaseBlock block) {
parent.setFullBlock(block);
}
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {
parent.setNbtData(nbtData);
}
@Override
public boolean hasNbtData() {
return parent.hasNbtData();
}
@Override
public void setBiome(BiomeType biome) {
parent.setBiome(biome);
}
@Override
public int getOrdinal() {
return parent.getOrdinal();
}
@Override
public BlockState getBlock() {
return parent.getBlock();
}
@Override
public BaseBlock getFullBlock() {
return parent.getFullBlock();
}
@Override
public CompoundTag getNbtData() {
return parent.getNbtData();
}
@Override
public BlockVector3 getMinimumPoint() {
return parent.getMinimumPoint();
}
@Override
public BlockVector3 getMaximumPoint() {
return parent.getMaximumPoint();
}
@Override
public BlockState getBlock(int x, int y, int z) {
return parent.getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return parent.getFullBlock(x, y, z);
}
@Override
public BlockState getBlockBelow() {
return parent.getBlockBelow();
}
@Override
public BlockState getBlockAbove() {
return parent.getBlockAbove();
}
@Override
public BlockState getBlockNorth() {
return parent.getBlockNorth();
}
@Override
public BlockState getBlockEast() {
return parent.getBlockEast();
}
@Override
public BlockState getBlockSouth() {
return parent.getBlockSouth();
}
@Override
public BlockState getBlockWest() {
return parent.getBlockWest();
}
@Override
public BlockState getBlockRelativeY(int y) {
return parent.getBlockRelativeY(y);
}
@Override
public int getX() {
return parent.getX();
}
@Override
public int getY() {
return parent.getY();
}
@Override
public int getZ() {
return parent.getZ();
}
@Override
public int getLocalX() {
return parent.getLocalX();
}
@Override
public int getLocalY() {
return parent.getLocalY();
}
@Override
public int getLocalZ() {
return parent.getLocalZ();
}
@Override
public int getChunkX() {
return parent.getChunkX();
}
@Override
public int getChunkZ() {
return parent.getChunkZ();
}
@Override
public boolean setOrdinal(Extent orDefault, int ordinal) {
return parent.setOrdinal(orDefault, ordinal);
}
@Override
public boolean setBlock(Extent orDefault, BlockState state) {
return parent.setBlock(orDefault, state);
}
@Override
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
return parent.setFullBlock(orDefault, block);
}
@Override
public boolean setBiome(Extent orDefault, BiomeType biome) {
return parent.setBiome(orDefault, biome);
}
@Override
public int getOrdinal(Extent orDefault) {
return parent.getOrdinal(orDefault);
}
@Override
public BlockState getBlock(Extent orDefault) {
return parent.getBlock(orDefault);
}
@Override
public BaseBlock getFullBlock(Extent orDefault) {
return parent.getFullBlock(orDefault);
}
@Override
public CompoundTag getNbtData(Extent orDefault) {
return parent.getNbtData(orDefault);
}
@Override
public BlockState getOrdinalBelow(Extent orDefault) {
return parent.getOrdinalBelow(orDefault);
}
@Override
public BlockState getStateAbove(Extent orDefault) {
return parent.getStateAbove(orDefault);
}
@Override
public BlockState getStateRelativeY(Extent orDefault, int y) {
return parent.getStateRelativeY(orDefault, y);
}
public static BlockVector3 at(double x, double y, double z) {
return BlockVector3.at(x, y, z);
}
public static BlockVector3 at(int x, int y, int z) {
return BlockVector3.at(x, y, z);
}
public static Comparator<BlockVector3> sortByCoordsYzx() {
return BlockVector3.sortByCoordsYzx();
}
@Override
public MutableBlockVector3 setComponents(double x, double y, double z) {
return parent.setComponents(x, y, z);
}
@Override
public MutableBlockVector3 setComponents(int x, int y, int z) {
return parent.setComponents(x, y, z);
}
@Override
public MutableBlockVector3 mutX(double x) {
return parent.mutX(x);
}
@Override
public MutableBlockVector3 mutY(double y) {
return parent.mutY(y);
}
@Override
public MutableBlockVector3 mutZ(double z) {
return parent.mutZ(z);
}
@Override
public MutableBlockVector3 mutX(int x) {
return parent.mutX(x);
}
@Override
public MutableBlockVector3 mutY(int y) {
return parent.mutY(y);
}
@Override
public MutableBlockVector3 mutZ(int z) {
return parent.mutZ(z);
}
@Override
public BlockVector3 toImmutable() {
return parent.toImmutable();
}
// @Override
// public BlockVector3 north() {
// return parent.north();
// }
//
// @Override
// public BlockVector3 east() {
// return parent.east();
// }
//
// @Override
// public BlockVector3 south() {
// return parent.south();
// }
//
// @Override
// public BlockVector3 west() {
// return parent.west();
// }
@Override
public int getBlockX() {
return parent.getBlockX();
}
@Override
public BlockVector3 withX(int x) {
return parent.withX(x);
}
@Override
public int getBlockY() {
return parent.getBlockY();
}
@Override
public BlockVector3 withY(int y) {
return parent.withY(y);
}
@Override
public int getBlockZ() {
return parent.getBlockZ();
}
@Override
public BlockVector3 withZ(int z) {
return parent.withZ(z);
}
@Override
public BlockVector3 add(BlockVector3 other) {
return parent.add(other);
}
@Override
public BlockVector3 add(int x, int y, int z) {
return parent.add(x, y, z);
}
@Override
public BlockVector3 add(BlockVector3... others) {
return parent.add(others);
}
@Override
public BlockVector3 subtract(BlockVector3 other) {
return parent.subtract(other);
}
@Override
public BlockVector3 subtract(int x, int y, int z) {
return parent.subtract(x, y, z);
}
@Override
public BlockVector3 subtract(BlockVector3... others) {
return parent.subtract(others);
}
@Override
public BlockVector3 multiply(BlockVector3 other) {
return parent.multiply(other);
}
@Override
public BlockVector3 multiply(int x, int y, int z) {
return parent.multiply(x, y, z);
}
@Override
public BlockVector3 multiply(BlockVector3... others) {
return parent.multiply(others);
}
@Override
public BlockVector3 multiply(int n) {
return parent.multiply(n);
}
@Override
public BlockVector3 divide(BlockVector3 other) {
return parent.divide(other);
}
@Override
public BlockVector3 divide(int x, int y, int z) {
return parent.divide(x, y, z);
}
@Override
public BlockVector3 divide(int n) {
return parent.divide(n);
}
@Override
public double length() {
return parent.length();
}
@Override
public int lengthSq() {
return parent.lengthSq();
}
@Override
public double distance(BlockVector3 other) {
return parent.distance(other);
}
@Override
public int distanceSq(BlockVector3 other) {
return parent.distanceSq(other);
}
@Override
public BlockVector3 normalize() {
return parent.normalize();
}
@Override
public double dot(BlockVector3 other) {
return parent.dot(other);
}
@Override
public BlockVector3 cross(BlockVector3 other) {
return parent.cross(other);
}
@Override
public boolean containedWithin(BlockVector3 min, BlockVector3 max) {
return parent.containedWithin(min, max);
}
@Override
public BlockVector3 clampY(int min, int max) {
return parent.clampY(min, max);
}
@Override
public BlockVector3 floor() {
return parent.floor();
}
@Override
public BlockVector3 ceil() {
return parent.ceil();
}
@Override
public BlockVector3 round() {
return parent.round();
}
@Override
public BlockVector3 abs() {
return parent.abs();
}
@Override
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
return parent.transform2D(angle, aboutX, aboutZ, translateX, translateZ);
}
@Override
public double toPitch() {
return parent.toPitch();
}
@Override
public double toYaw() {
return parent.toYaw();
}
@Override
public BlockVector3 getMinimum(BlockVector3 v2) {
return parent.getMinimum(v2);
}
@Override
public BlockVector3 getMaximum(BlockVector3 v2) {
return parent.getMaximum(v2);
}
@Override
public char getOrdinalChar(Extent orDefault) {
return parent.getOrdinalChar(orDefault);
}
@Override
public BlockVector2 toBlockVector2() {
return parent.toBlockVector2();
}
@Override
public Vector3 toVector3() {
return parent.toVector3();
}
@Override
public int hashCode() {
return parent.hashCode();
}
@Override
public String toString() {
return parent.toString();
}
@Override
public List<? extends Entity> getEntities(Region region) {
return parent.getEntities(region);
}
@Override
public List<? extends Entity> getEntities() {
return parent.getEntities();
}
@Override
@Nullable
public Entity createEntity(Location location, BaseEntity entity) {
return parent.createEntity(location, entity);
}
@Override
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
return parent.getHighestTerrainBlock(x, z, minY, maxY);
}
@Override
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
return parent.getHighestTerrainBlock(x, z, minY, maxY, filter);
}
@Override
public int getNearestSurfaceLayer(int x, int z, int y, int minY, int maxY) {
return parent.getNearestSurfaceLayer(x, z, y, minY, maxY);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, boolean ignoreAir) {
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, ignoreAir);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) {
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) {
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, Mask mask) {
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, mask);
}
@Override
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) {
return parent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY, failedMin, failedMax, ignoreAir);
}
@Override
public void addCaves(Region region) throws WorldEditException {
parent.addCaves(region);
}
@Override
public void generate(Region region, GenBase gen) throws WorldEditException {
parent.generate(region, gen);
}
@Override
public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException {
parent.addSchems(region, mask, clipboards, rarity, rotate);
}
@Override
public void spawnResource(Region region, Resource gen, int rarity, int frequency) throws WorldEditException {
parent.spawnResource(region, gen, rarity, frequency);
}
@Override
public boolean contains(BlockVector3 pt) {
return parent.contains(pt);
}
@Override
public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException {
parent.addOre(region, mask, material, size, frequency, rarity, minY, maxY);
}
@Override
public void addOres(Region region, Mask mask) throws WorldEditException {
parent.addOres(region, mask);
}
@Override
public List<Countable<BlockType>> getBlockDistribution(Region region) {
return parent.getBlockDistribution(region);
}
@Override
public List<Countable<BlockState>> getBlockDistributionWithData(Region region) {
return parent.getBlockDistributionWithData(region);
}
@Override
public BlockArrayClipboard lazyCopy(Region region) {
return parent.lazyCopy(region);
}
@Override
@Nullable
public Operation commit() {
return parent.commit();
}
@Override
public int getMaxY() {
return parent.getMaxY();
}
@Override
public BlockState getBlock(BlockVector3 position) {
return parent.getBlock(position);
}
@Override
public BlockType getBlockType(BlockVector3 position) {
return parent.getBlockType(position);
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return parent.getFullBlock(position);
}
@Override
public BiomeType getBiome(BlockVector2 position) {
return parent.getBiome(position);
}
@Override
public BiomeType getBiomeType(int x, int z) {
return parent.getBiomeType(x, z);
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
return parent.setBlock(position, block);
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
return parent.setBlock(x, y, z, block);
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
return parent.setBiome(position, biome);
}
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
return parent.setBiome(x, y, z, biome);
}
@Override
public String getNbtId() {
return parent.getNbtId();
}
}

Datei anzeigen

@ -0,0 +1,5 @@
package com.boydti.fawe.beta;
public interface DirectionMask {
boolean apply(int fromX, int fromY, int fromZ, int toX, int toY, int toZ);
}

Datei anzeigen

@ -0,0 +1,70 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
import javax.annotation.Nullable;
/**
* A filter is an interface used for setting blocks
*/
public interface Filter {
/**
* Check whether a chunk should be read
*
* @param cx
* @param cz
* @return
*/
default boolean appliesChunk(final int cx, final int cz) {
return true;
}
/**
* Do something with the IChunk<br>
* - Return null if you don't want to filter blocks<br>
* - Return the chunk if you do want to filter blocks<br>
*
* @param chunk
* @return
*/
default IChunk applyChunk(final IChunk chunk, @Nullable Region region) {
return chunk;
}
default boolean appliesLayer(IChunk chunk, int layer) {
return true;
}
/**
* Make changes to the block here<br>
* - e.g. block.setId(...)<br>
* - Note: Performance is critical here<br>
*
* @param block
*/
default void applyBlock(final FilterBlock block) {
}
/**
* Do something with the IChunk after block filtering<br>
*
* @param chunk
* @return
*/
default void finishChunk(final IChunk chunk) {
}
/**
* Fork this for use by another thread
* - Typically filters are simple and don't need to create another copy to be thread safe here
* @return this
*/
default Filter fork() {
return this;
}
default void join() {
}
}

Datei anzeigen

@ -0,0 +1,169 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import javax.annotation.Nullable;
import static com.sk89q.worldedit.world.block.BlockTypes.states;
public abstract class FilterBlock extends BlockVector3 implements Extent, TileEntityBlock {
public abstract Extent getExtent();
public abstract void setOrdinal(int ordinal);
public abstract void setBlock(BlockState state);
public abstract void setFullBlock(BaseBlock block);
public void setBiome(BiomeType biome) {
setBiome(getX(), getY(), getZ(), biome);
}
public abstract int getOrdinal();
public abstract BlockState getBlock();
public abstract BaseBlock getFullBlock();
public abstract CompoundTag getNbtData();
public abstract void setNbtData(@Nullable CompoundTag nbtData);
public boolean hasNbtData() {
return getNbtData() != null;
}
@Override
public BlockVector3 getMinimumPoint() {
return getExtent().getMinimumPoint();
}
@Override
public BlockVector3 getMaximumPoint() {
return getExtent().getMaximumPoint();
}
@Override
public BlockState getBlock(int x, int y, int z) {
return getExtent().getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return getExtent().getFullBlock(x, y, z);
}
public BlockState getBlockBelow() {
return getBlock(getX(), getY() - 1, getZ());
}
public BlockState getBlockAbove() {
return getBlock(getX(), getY() + 1, getZ());
}
public BlockState getBlockNorth() {
return getBlock(getX(), getY(), getZ() - 1);
}
public BlockState getBlockEast() {
return getBlock(getX() + 1, getY(), getZ());
}
public BlockState getBlockSouth() {
return getBlock(getX(), getY(), getZ() + 1);
}
public BlockState getBlockWest() {
return getBlock(getX() - 1, getY(), getZ());
}
public BlockState getBlockRelativeY(final int y) {
return getBlock(getX(), getY() + y , getZ());
}
@Override
public abstract int getX();
@Override
public abstract int getY();
@Override
public abstract int getZ();
public int getLocalX() {
return getX() & 15;
}
public int getLocalY() {
return getY() & 15;
}
public int getLocalZ() {
return getZ() & 15;
}
public int getChunkX() {
return getX() >> 4;
}
public int getChunkZ() {
return getZ() >> 4;
}
/*
Extent
*/
public boolean setOrdinal(Extent orDefault, int ordinal) {
setOrdinal(ordinal);
return true;
}
public boolean setBlock(Extent orDefault, BlockState state) {
setBlock(state);
return true;
}
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
setFullBlock(block);
return true;
}
public boolean setBiome(Extent orDefault, BiomeType biome) {
setBiome(biome);
return true;
}
public int getOrdinal(Extent orDefault) {
return getOrdinal();
}
public BlockState getBlock(Extent orDefault) {
return getBlock();
}
public BaseBlock getFullBlock(Extent orDefault) {
return getFullBlock();
}
public CompoundTag getNbtData(Extent orDefault) {
return getNbtData();
}
public BlockState getOrdinalBelow(Extent orDefault) {
return getBlockBelow();
}
public BlockState getStateAbove(Extent orDefault) {
return getBlockAbove();
}
public BlockState getStateRelativeY(Extent orDefault, final int y) {
return getBlockRelativeY(y);
}
}

Datei anzeigen

@ -0,0 +1,5 @@
package com.boydti.fawe.beta;
public interface FilterBlockMask {
boolean applyBlock(final FilterBlock block);
}

Datei anzeigen

@ -0,0 +1,193 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.World;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
public class Flood {
private final int maxBranch;
private final int maxDepth;
private final Direction[] directions;
private int[] queue;
private long[] visit;
private int[][] queues;
private long[][] visits;
private int X, Y, Z;
private ConcurrentLinkedQueue<int[]> queuePool = new ConcurrentLinkedQueue<>();
private final Long2ObjectLinkedOpenHashMap<long[][]> chunkVisits;
private final Long2ObjectLinkedOpenHashMap<int[][]> chunkQueues;
public Flood(int maxBranch, int maxDepth, Direction[] directions) {
this.maxBranch = maxBranch;
this.maxDepth = maxDepth;
this.directions = directions;
this.queues = new int[27][];
this.visits = new long[27][];
this.chunkVisits = new Long2ObjectLinkedOpenHashMap<>();
this.chunkQueues = new Long2ObjectLinkedOpenHashMap<>();
}
public synchronized void run(World world) {
QueueHandler queueHandler = Fawe.get().getQueueHandler();
IQueueExtent fq = queueHandler.getQueue(world);
while (!chunkQueues.isEmpty()) {
long firstKey = chunkQueues.firstLongKey();
int X = MathMan.unpairIntX(firstKey);
int Z = MathMan.unpairIntY(firstKey);
int[][] chunkQueue = chunkQueues.get(firstKey);
// apply
TODO
}
}
private void init(int X, int Y, int Z) {
this.X = X;
this.Y = Y;
this.Z = Z;
}
public void start(int x, int y, int z) {
push(x, y, z, 0);
}
private void push(int x, int y, int z, int depth) {
int X = x >> 4;
int Z = z >> 4;
long pair = MathMan.pairInt(X, Z);
int layer = y >> 4;
int[] section = getOrCreateQueue(pair, layer);
int val = (x & 15) + ((z & 15) << 4) + ((y & 15) << 8) + (depth << 12);
push(section, val);
}
private int[] getOrCreateQueue(long pair, int layer) {
int[][] arrs = chunkQueues.get(pair);
if (arrs == null) {
chunkQueues.put(pair, arrs = new int[16][]);
}
int[] section = arrs[layer];
if (section == null) {
arrs[layer] = section = newQueue();
}
return section;
}
private int[] newQueue() {
int[] arr = queuePool.poll();
if (arr != null) {
arr[0] = 2;
arr[1] = 2;
return arr;
}
return new int[4096];
}
public int poll() {
int index = queue[0];
if (index == queue[1]) {
return -1;
}
queue[0] = index + 1;
return queue[index];
}
private void push(int[] queue, int val) {
int indexStart = queue[0];
int indexEnd = queue[1];
push(indexStart, indexEnd, queue, val);
}
private void push(int indexStart, int indexEnd, int[] queue, int val) {
if (indexStart > 2) {
queue[0] = --indexStart;
queue[indexStart] = val;
} else {
queue[indexEnd] = val;
queue[0] = ++indexEnd;
}
}
public Direction[] getDirections() {
return directions;
}
public int getMaxBranch() {
return maxBranch;
}
public int getMaxDepth() {
return maxDepth;
}
public void apply(int x, int y, int z, int depth) {
for (int i = 0, j = 0; i < directions.length && j < maxBranch; i++) {
final Direction dir = directions[i];
final int ty = y + dir.getBlockY();
final int tx = x + dir.getBlockX();
final int tz = z + dir.getBlockZ();
int index;
long[] visit;
int[] queue;
final int or = tx | ty | tz;
if (or > 15 || or < 0) {
visit = this.visit;
queue = this.queue;
index = tx + (tz << 4) + (ty << 8);
} else {
int nextX = tx >> 4;
int nextY = ty >> 4;
int nextZ = tz >> 4;
int sectionIndex = nextX + nextZ * 3 + nextZ * 9 + 13;
visit = visits[sectionIndex];
queue = queues[sectionIndex];
if (visit == null || queue == null) {
long pair = MathMan.pairInt(X + nextX, Z + nextZ);
int layer = Y + nextY;
if (layer < 0 || layer > 15) {
continue;
}
queues[sectionIndex] = queue = getOrCreateQueue(pair, layer);
}
index = (tx & 15) + ((tz & 15) << 4) + ((ty & 15) << 8);
}
if (!getAndSet(visit, index)) {
j++;
push(queue, index + (depth << 12));
}
}
}
public void set(long[] bits, int i) {
bits[i >> 6] |= (1L << (i & 0x3F));
}
public final boolean getAndSet(long[] bits, int i) {
int index = i >> 6;
long offset = (1L << (i & 0x3F));
long val = bits[index];
if ((val & offset) != 0) {
return true;
} else {
bits[index] |= offset;
return false;
}
}
public boolean get(long[] bits, final int i) {
return (bits[i >> 6] & (1L << (i & 0x3F))) != 0;
}
}

Datei anzeigen

@ -0,0 +1,10 @@
package com.boydti.fawe.beta;
/**
* Shared interface for IGetBlocks and ISetBlocks
*/
public interface IBlocks extends Trimable {
boolean hasSection(int layer);
IChunkSet reset();
}

Datei anzeigen

@ -0,0 +1,89 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* Represents a chunk in the queue {@link IQueueExtent}
* Used for getting and setting blocks / biomes / entities
*/
public interface IChunk<T extends Future<T>> extends Trimable, Callable<T> {
/**
* Initialize at the location
* @param extent
* @param X
* @param Z
*/
void init(IQueueExtent extent, int X, int Z);
int getX();
int getZ();
/**
* If the chunk is a delegate, returns it's paren'ts root
* @return root IChunk
*/
default IChunk getRoot() {
return this;
}
/**
* @return true if no changes are queued for this chunk
*/
boolean isEmpty();
/**
* Apply the queued changes to the world<br>
* The future returned may return another future<br>
* To ensure completion keep calling {@link Future#get()} on each result
* @return Futures
*/
T call();
/**
* Call and join
* @throws ExecutionException
* @throws InterruptedException
*/
default void join() throws ExecutionException, InterruptedException {
T future = call();
while (future != null) {
future = future.get();
}
return;
}
/**
* Filter
* @param filter the filter
* @param block The filter block
* @param region The region allowed to filter (may be null)
* @param unitialized a mutable block vector (buffer)
* @param unitialized2 a mutable block vector (buffer)
*/
void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region);
void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block);
/* set - queues a change */
boolean setBiome(int x, int y, int z, BiomeType biome);
boolean setBlock(int x, int y, int z, BlockStateHolder block);
/* get - from the world */
BiomeType getBiome(int x, int z);
BlockState getBlock(int x, int y, int z);
BaseBlock getFullBlock(int x, int y, int z);
}

Datei anzeigen

@ -0,0 +1,30 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.InputExtent;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
/**
* Interface for getting blocks
*/
public interface IChunkGet extends IBlocks, Trimable, InputExtent {
@Override
BaseBlock getFullBlock(int x, int y, int z);
@Override
BiomeType getBiomeType(int x, int z);
@Override
BlockState getBlock(int x, int y, int z);
CompoundTag getTag(int x, int y, int z);
@Override
boolean trim(boolean aggressive);
default void optimize() {
}
}

Datei anzeigen

@ -0,0 +1,51 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.OutputExtent;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/**
* Interface for setting blocks
*/
public interface IChunkSet extends IBlocks, OutputExtent {
boolean setBiome(int x, int y, int z, BiomeType biome);
boolean setBlock(int x, int y, int z, BlockStateHolder holder);
boolean isEmpty();
void setTile(int x, int y, int z, CompoundTag tile);
void setEntity(CompoundTag tag);
void removeEntity(UUID uuid);
BlockState getBlock(int x, int y, int z);
char[] getArray(int layer);
BiomeType[] getBiomes();
Map<Short, CompoundTag> getTiles();
Set<CompoundTag> getEntities();
Set<UUID> getEntityRemoves();
@Override
IChunkSet reset();
@Nullable
@Override
default Operation commit() {
return null;
}
}

Datei anzeigen

@ -0,0 +1,109 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* Delegate for IChunk
* @param <U> parent class
*/
public interface IDelegateChunk<U extends IChunk> extends IChunk {
U getParent();
default IChunk getRoot() {
IChunk root = getParent();
while (root instanceof IDelegateChunk) {
root = ((IDelegateChunk) root).getParent();
}
return root;
}
@Override
default void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) {
getParent().flood(flood, mask, block);
}
@Override
default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
return getParent().setBiome(x, y, z, biome);
}
@Override
default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder holder) {
return getParent().setBlock(x, y, z, holder);
}
@Override
default BiomeType getBiome(final int x, final int z) {
return getParent().getBiome(x, z);
}
@Override
default BlockState getBlock(final int x, final int y, final int z) {
return getParent().getBlock(x, y, z);
}
@Override
default BaseBlock getFullBlock(final int x, final int y, final int z) {
return getParent().getFullBlock(x, y, z);
}
@Override
default void init(final IQueueExtent extent, final int X, final int Z) {
getParent().init(extent, X, Z);
}
@Override
default int getX() {
return getParent().getX();
}
@Override
default int getZ() {
return getParent().getZ();
}
@Override
default boolean trim(final boolean aggressive) {
return getParent().trim(aggressive);
}
@Override
default Future call() {
return getParent().call();
}
@Override
default void join() throws ExecutionException, InterruptedException {
getParent().join();
}
@Override
default void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region) {
getParent().filterBlocks(filter, block, region);
}
@Override
default boolean isEmpty() {
return getParent().isEmpty();
}
default <T extends IChunk> T findParent(final Class<T> clazz) {
IChunk root = getParent();
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
while (root instanceof IDelegateChunk) {
root = ((IDelegateChunk) root).getParent();
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
}
return null;
}
}

Datei anzeigen

@ -0,0 +1,50 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable;
public interface IDelegateFilter extends Filter {
Filter getParent();
@Override
default boolean appliesChunk(int cx, int cz) {
return getParent().appliesChunk(cx, cz);
}
@Override
default IChunk applyChunk(IChunk chunk, @Nullable Region region) {
return getParent().applyChunk(chunk, region);
}
@Override
default boolean appliesLayer(IChunk chunk, int layer) {
return getParent().appliesLayer(chunk, layer);
}
@Override
default void applyBlock(FilterBlock block) {
getParent().applyBlock(block);
}
@Override
default void finishChunk(IChunk chunk) {
getParent().finishChunk(chunk);
}
@Override
default void join() {
getParent().join();
}
@Override
default Filter fork() {
Filter fork = getParent().fork();
if (fork != getParent()) {
return newInstance(fork);
}
return this;
}
Filter newInstance(Filter other);
}

Datei anzeigen

@ -0,0 +1,47 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import java.util.concurrent.Future;
/**
* Delegate for IQueueExtent
*/
public interface IDelegateQueueExtent extends IQueueExtent {
IQueueExtent getParent();
@Override
default void init(final WorldChunkCache cache) {
getParent().init(cache);
}
@Override
default IChunk getCachedChunk(final int X, final int Z) {
return getParent().getCachedChunk(X, Z);
}
@Override
default Future<?> submit(final IChunk chunk) {
return getParent().submit(chunk);
}
@Override
default IChunk create(final boolean full) {
return getParent().create(full);
}
@Override
default IChunk wrap(final IChunk root) {
return getParent().wrap(root);
}
@Override
default void flush() {
getParent().flush();
}
@Override
default boolean trim(final boolean aggressive) {
return getParent().trim(aggressive);
}
}

Datei anzeigen

@ -0,0 +1,103 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.io.Flushable;
import java.util.concurrent.Future;
/**
* TODO: implement Extent (need to refactor Extent first)
* Interface for a queue based extent which uses chunks
*/
public interface IQueueExtent extends Flushable, Trimable, Extent {
void init(WorldChunkCache world);
/**
* Get the {@link WorldChunkCache}
* @return
*/
WorldChunkCache getCache();
/**
* Get the IChunk at a position (and cache it if it's not already)
* @param X
* @param Z
* @return IChunk
*/
IChunk getCachedChunk(int X, int Z);
/**
* Submit the chunk so that it's changes are applied to the world
* @param chunk
* @return result
*/
<T extends Future<T>> T submit(IChunk<T> chunk);
default boolean setBlock(final int x, final int y, final int z, final BlockStateHolder state) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.setBlock(x & 15, y, z & 15, state);
}
default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.setBiome(x & 15, y, z & 15, biome);
}
default BlockState getBlock(final int x, final int y, final int z) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBlock(x & 15, y, z & 15);
}
@Override
default BaseBlock getFullBlock(int x, int y, int z) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getFullBlock(x & 15, y, z & 15);
}
default BiomeType getBiome(final int x, final int z) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBiome(x & 15, z & 15);
}
@Override
default BlockVector3 getMinimumPoint() {
return getCache().getWorld().getMinimumPoint();
}
@Override
default BlockVector3 getMaximumPoint() {
return getCache().getWorld().getMaximumPoint();
}
/**
* Create a new root IChunk object<br>
* - Full chunks will be reused, so a more optimized chunk can be returned in that case<br>
* - Don't wrap the chunk, that should be done in {@link #wrap(IChunk)}
* @param full
* @return
*/
IChunk create(boolean full);
/**
* Wrap the chunk object (i.e. for region restrictions / limits etc.)
* @param root
* @return wrapped chunk
*/
default IChunk wrap(final IChunk root) {
return root;
}
/**
* Flush all changes to the world
* - Best to call this async so it doesn't hang the server
*/
@Override
void flush();
ChunkFilterBlock initFilterBlock();
}

Datei anzeigen

@ -0,0 +1,92 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
public class NorthVector extends BlockVector3 {
private final BlockVector3 parent;
public NorthVector(BlockVector3 parent) {
this.parent = parent;
}
// @Override
// public BlockVector3 south(BlockVector3 orDefault) {
// return parent;
// }
@Override
public int getX() {
return parent.getX();
}
@Override
public int getY() {
return parent.getY();
}
@Override
public int getZ() {
return parent.getZ();
}
public boolean setOrdinal(Extent orDefault, int ordinal) {
return orDefault.setBlock(this, BlockState.getFromOrdinal(ordinal));
}
public boolean setBlock(Extent orDefault, BlockState state) {
return orDefault.setBlock(this, state);
}
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
return orDefault.setBlock(this, block);
}
public boolean setBiome(Extent orDefault, BiomeType biome) {
return orDefault.setBiome(getX(), getY(), getZ(), biome);
}
public int getOrdinal(Extent orDefault) {
return getBlock(orDefault).getOrdinal();
}
public char getOrdinalChar(Extent orDefault) {
return (char) getOrdinal(orDefault);
}
public BlockState getBlock(Extent orDefault) {
return orDefault.getBlock(this);
}
public BaseBlock getFullBlock(Extent orDefault) {
return orDefault.getFullBlock(this);
}
public CompoundTag getNbtData(Extent orDefault) {
return orDefault.getFullBlock(getX(), getY(), getZ()).getNbtData();
}
public BlockState getOrdinalBelow(Extent orDefault) {
return getStateRelative(orDefault, 0, -1, 0);
}
public BlockState getStateAbove(Extent orDefault) {
return getStateRelative(orDefault, 0, 1, 0);
}
public BlockState getStateRelativeY(Extent orDefault, final int y) {
return getStateRelative(orDefault, 0, y, 0);
}
public BlockState getStateRelative(Extent orDefault, final int x, final int y, final int z) {
return getFullBlockRelative(orDefault, x, y, z).toBlockState();
}
public BaseBlock getFullBlockRelative(Extent orDefault, int x, int y, int z) {
return orDefault.getFullBlock(x + getX(), y + getY(), z + getZ());
}
}

Datei anzeigen

@ -0,0 +1,16 @@
package com.boydti.fawe.beta;
import com.sk89q.worldedit.extent.Extent;
public abstract class SimpleFilterBlock extends FilterBlock {
private final Extent extent;
public SimpleFilterBlock(Extent extent) {
this.extent = extent;
}
@Override
public final Extent getExtent() {
return extent;
}
}

Datei anzeigen

@ -0,0 +1,98 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import javax.annotation.Nullable;
public class SingleFilterBlock extends FilterBlock {
private BaseBlock block;
private int x, y, z;
public SingleFilterBlock init(int x, int y, int z, BaseBlock block) {
this.x = x;
this.y = y;
this.z = z;
this.block = block;
return this;
}
@Override
public Extent getExtent() {
return this;
}
@Override
public void setOrdinal(int ordinal) {
setBlock(BlockState.getFromOrdinal(ordinal));
}
@Override
public void setBlock(BlockState state) {
setFullBlock(state.toBaseBlock(block.getNbtData()));
}
@Override
public void setFullBlock(BaseBlock block) {
this.block = block;
}
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {
block = block.toBaseBlock(nbtData);
}
@Override
public int getOrdinal() {
return block.getOrdinal();
}
// @Override
// public BaseBlock getFullBlockRelative(int x, int y, int z) {
// return block;
// }
@Override
public BlockState getBlock() {
return block.toBlockState();
}
@Override
public BaseBlock getFullBlock() {
return block;
}
@Override
public CompoundTag getNbtData() {
return block.getNbtData();
}
@Override
public int getX() {
return x;
}
@Override
public int getY() {
return y;
}
@Override
public int getZ() {
return z;
}
@Override
public BlockVector3 getMinimumPoint() {
return BlockVector3.at(x, y, z);
}
@Override
public BlockVector3 getMaximumPoint() {
return BlockVector3.at(x, y, z);
}
}

Datei anzeigen

@ -0,0 +1,14 @@
package com.boydti.fawe.beta;
/**
* Interface for objects that can be trimmed (memory related)<br>
* - Trimming will reduce it's memory footprint
*/
public interface Trimable {
/**
* Trim the object, reducing it's memory footprint
* @param aggressive if trimming should be aggressive e.g. Not return early when the first element cannot be trimmed
* @return if this object is empty at the end of the trim, and can therefore be deleted
*/
boolean trim(boolean aggressive);
}

Datei anzeigen

@ -0,0 +1,26 @@
package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.DelegateFilter;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.FilterBlockMask;
import java.awt.image.BufferedImage;
import java.util.concurrent.ThreadLocalRandom;
public class ArrayImageMask implements FilterBlockMask {
private final ThreadLocalRandom r;
private final boolean white;
private final BufferedImage img;
public ArrayImageMask(BufferedImage img, boolean white) {
this.img = img;
this.white = white;
this.r = ThreadLocalRandom.current();
}
@Override
public boolean applyBlock(FilterBlock block) {
int height = img.getRGB(block.getX(), block.getZ()) & 0xFF;
return ((height == 255 || height > 0 && !white && r.nextInt(256) <= height));
}
}

Datei anzeigen

@ -0,0 +1,68 @@
package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.config.BBC;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CountFilter extends ForkedFilter<CountFilter> {
private final int[] counter = new int[BlockTypes.states.length];
public CountFilter() {
super(null);
}
private CountFilter(CountFilter root) {
super(root);
}
@Override
public CountFilter init() {
return new CountFilter(this);
}
@Override
public void join(CountFilter filter) {
for (int i = 0; i < filter.counter.length; i++) {
this.counter[i] += filter.counter[i];
}
}
/*
Implementation
*/
@Override
public final void applyBlock(final FilterBlock block) {
counter[block.getOrdinal()]++;
}
public List<Countable<BlockState>> getDistribution() {
final List<Countable<BlockState>> distribution = new ArrayList<>();
for (int i = 0; i < counter.length; i++) {
final int count = counter[i];
if (count != 0) {
distribution.add(new Countable<>(BlockTypes.states[i], count));
}
}
Collections.sort(distribution);
return distribution;
}
public void print(final Actor actor, final long size) {
for (final Countable c : getDistribution()) {
final String name = c.getID().toString();
final String str = String.format("%-7s (%.3f%%) %s",
String.valueOf(c.getAmount()),
c.getAmount() / (double) size * 100,
name);
actor.print(BBC.getPrefix() + str);
}
}
}

Datei anzeigen

@ -0,0 +1,48 @@
package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.config.BBC;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public abstract class ForkedFilter<T extends ForkedFilter<T>> implements Filter {
protected final Map<Thread, T> children;
public ForkedFilter(T root) {
if (root != null) {
children = root.children;
} else {
children = new ConcurrentHashMap<>();
children.put(Thread.currentThread(), (T) this);
}
}
@Override
public final Filter fork() {
return children.computeIfAbsent(Thread.currentThread(), thread -> init());
}
public abstract T init();
@Override
public void join() {
for (Map.Entry<Thread, T> entry : children.entrySet()) {
T filter = entry.getValue();
if (filter != this) {
join(filter);
}
}
children.clear();
}
public abstract void join(T filter);
}

Datei anzeigen

@ -0,0 +1,18 @@
package com.boydti.fawe.beta.filters;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.worldedit.world.block.BlockState;
public class SetFilter implements Filter {
private final BlockState state;
public SetFilter(final BlockState state) {
this.state = state;
}
@Override
public void applyBlock(final FilterBlock block) {
block.setBlock(state);
}
}

Datei anzeigen

@ -0,0 +1,113 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public interface DelegateChunkSet extends IChunkSet {
IChunkSet getParent();
@Override
default boolean setBiome(int x, int y, int z, BiomeType biome) {
return getParent().setBiome(x, y, z, biome);
}
@Override
default boolean setBlock(int x, int y, int z, BlockStateHolder holder) {
return getParent().setBlock(x, y, z, holder);
}
@Override
default boolean isEmpty() {
return getParent().isEmpty();
}
@Override
default void setTile(int x, int y, int z, CompoundTag tile) {
getParent().setTile(x, y, z, tile);
}
@Override
default void setEntity(CompoundTag tag) {
getParent().setEntity(tag);
}
@Override
default void removeEntity(UUID uuid) {
getParent().removeEntity(uuid);
}
@Override
default BlockState getBlock(int x, int y, int z) {
return getParent().getBlock(x, y, z);
}
@Override
default char[] getArray(int layer) {
return getParent().getArray(layer);
}
@Override
default BiomeType[] getBiomes() {
return getParent().getBiomes();
}
@Override
default Map<Short, CompoundTag> getTiles() {
return getParent().getTiles();
}
@Override
default Set<CompoundTag> getEntities() {
return getParent().getEntities();
}
@Override
default Set<UUID> getEntityRemoves() {
return getParent().getEntityRemoves();
}
@Override
default IChunkSet reset() {
IChunkSet parent = getParent();
parent.reset();
return parent;
}
@Override
@Nullable
default Operation commit() {
return getParent().commit();
}
@Override
default boolean hasSection(int layer) {
return getParent().hasSection(layer);
}
@Override
default boolean trim(boolean aggressive) {
return getParent().trim(aggressive);
}
@Override
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
return getParent().setBlock(position, block);
}
@Override
default boolean setBiome(BlockVector2 position, BiomeType biome) {
return getParent().setBiome(position, biome);
}
}

Datei anzeigen

@ -0,0 +1,203 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.Trimable;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.collection.IterableThreadLocal;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.wrappers.WorldWrapper;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Class which handles all the queues {@link IQueueExtent}
*/
public abstract class QueueHandler implements Trimable, Runnable {
private ForkJoinPool forkJoinPoolPrimary = new ForkJoinPool();
private ForkJoinPool forkJoinPoolSecondary = new ForkJoinPool();
private ThreadPoolExecutor blockingExecutor = FaweCache.newBlockingExecutor();
private ConcurrentLinkedQueue<FutureTask> syncTasks = new ConcurrentLinkedQueue();
private Map<World, WeakReference<WorldChunkCache>> chunkCache = new HashMap<>();
private IterableThreadLocal<IQueueExtent> queuePool = new IterableThreadLocal<IQueueExtent>() {
@Override
public IQueueExtent init() {
return create();
}
};
public QueueHandler() {
TaskManager.IMP.repeat(this, 1);
}
@Override
public void run() {
if (!Fawe.isMainThread()) {
throw new IllegalStateException("Not main thread");
}
while (!syncTasks.isEmpty()) {
final FutureTask task = syncTasks.poll();
if (task != null) task.run();
}
}
public <T> Future<T> async(final Runnable run, final T value) {
return forkJoinPoolSecondary.submit(run, value);
}
public <T> Future<T> async(final Callable<T> call) {
return forkJoinPoolSecondary.submit(call);
}
public <T> Future<T> sync(final Runnable run, final T value) {
final FutureTask<T> result = new FutureTask<>(run, value);
syncTasks.add(result);
return result;
}
public <T> Future<T> sync(final Runnable run) {
final FutureTask<T> result = new FutureTask<>(run, null);
syncTasks.add(result);
return result;
}
public <T> Future<T> sync(final Callable<T> call) {
final FutureTask<T> result = new FutureTask<>(call);
syncTasks.add(result);
return result;
}
public <T extends Future<T>> T submit(final IChunk<T> chunk) {
if (MemUtil.isMemoryFree()) {
// return (T) forkJoinPoolSecondary.submit(chunk);
}
return (T) blockingExecutor.submit(chunk);
}
/**
* Get or create the WorldChunkCache for a world
* @param world
* @return
*/
public WorldChunkCache getOrCreate(World world) {
world = WorldWrapper.unwrap(world);
synchronized (chunkCache) {
final WeakReference<WorldChunkCache> ref = chunkCache.get(world);
if (ref != null) {
final WorldChunkCache cached = ref.get();
if (cached != null) {
return cached;
}
}
final WorldChunkCache created = new WorldChunkCache(world);
chunkCache.put(world, new WeakReference<>(created));
return created;
}
}
public abstract IQueueExtent create();
public IQueueExtent getQueue(final World world) {
final IQueueExtent queue = queuePool.get();
queue.init(getOrCreate(world));
return queue;
}
@Override
public boolean trim(final boolean aggressive) {
boolean result = true;
synchronized (chunkCache) {
final Iterator<Map.Entry<World, WeakReference<WorldChunkCache>>> iter = chunkCache.entrySet().iterator();
while (iter.hasNext()) {
final Map.Entry<World, WeakReference<WorldChunkCache>> entry = iter.next();
final WeakReference<WorldChunkCache> value = entry.getValue();
final WorldChunkCache cache = value.get();
if (cache == null || cache.size() == 0 || cache.trim(aggressive)) {
iter.remove();
continue;
}
result = false;
}
}
return result;
}
public void apply(final World world, final Region region, final Filter filter) {
// The chunks positions to iterate over
final Set<BlockVector2> chunks = region.getChunks();
final Iterator<BlockVector2> chunksIter = chunks.iterator();
// Get a pool, to operate on the chunks in parallel
final int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS);
final ForkJoinTask[] tasks = new ForkJoinTask[size];
for (int i = 0; i < size; i++) {
tasks[i] = forkJoinPoolPrimary.submit(new Runnable() {
@Override
public void run() {
final Filter newFilter = filter.fork();
// Create a chunk that we will reuse/reset for each operation
final IQueueExtent queue = getQueue(world);
synchronized (queue) {
ChunkFilterBlock block = null;
while (true) {
// Get the next chunk posWeakChunk
final int X, Z;
synchronized (chunksIter) {
if (!chunksIter.hasNext()) break;
final BlockVector2 pos = chunksIter.next();
X = pos.getX();
Z = pos.getZ();
}
if (!newFilter.appliesChunk(X, Z)) {
continue;
}
IChunk chunk = queue.getCachedChunk(X, Z);
// Initialize
chunk.init(queue, X, Z);
IChunk newChunk = newFilter.applyChunk(chunk, region);
if (newChunk != null) {
chunk = newChunk;
if (block == null) block = queue.initFilterBlock();
chunk.filterBlocks(newFilter, block, region);
}
queue.submit(chunk);
}
queue.flush();
}
}
});
}
// Join filters
for (int i = 0; i < tasks.length; i++) {
final ForkJoinTask task = tasks[i];
if (task != null) {
task.quietlyJoin();
}
}
filter.join();
}
}

Datei anzeigen

@ -0,0 +1,12 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.CharFilterBlock;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.FilterBlock;
public abstract class SimpleCharQueueExtent extends SingleThreadQueueExtent {
@Override
public ChunkFilterBlock initFilterBlock() {
return new CharFilterBlock(this);
}
}

Datei anzeigen

@ -0,0 +1,252 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.holder.ReferenceChunk;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.MemUtil;
import com.google.common.util.concurrent.Futures;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Single threaded implementation for IQueueExtent (still abstract)
* - Does not implement creation of chunks (that has to implemented by the platform e.g. Bukkit)
*
* This queue is reusable {@link #init(WorldChunkCache)}
*/
public abstract class SingleThreadQueueExtent implements IQueueExtent {
private WorldChunkCache cache;
private Thread currentThread;
private ConcurrentLinkedQueue<Future> submissions = new ConcurrentLinkedQueue<>();
/**
* Safety check to ensure that the thread being used matches the one being initialized on
* - Can be removed later
*/
private void checkThread() {
if (Thread.currentThread() != currentThread && currentThread != null) {
throw new UnsupportedOperationException("This class must be used from a single thread. Use multiple queues for concurrent operations");
}
}
@Override
public WorldChunkCache getCache() {
return cache;
}
/**
* Reset the queue
*/
protected synchronized void reset() {
checkThread();
cache = null;
if (!chunks.isEmpty()) {
CHUNK_POOL.addAll(chunks.values());
chunks.clear();
}
lastChunk = null;
lastPair = Long.MAX_VALUE;
currentThread = null;
}
/**
* Initialize the queue
* @param cache
*/
@Override
public synchronized void init(final WorldChunkCache cache) {
if (this.cache != null) {
reset();
}
currentThread = Thread.currentThread();
checkNotNull(cache);
this.cache = cache;
}
// Last access pointers
private IChunk lastChunk;
private long lastPair = Long.MAX_VALUE;
// Chunks currently being queued / worked on
private final Long2ObjectLinkedOpenHashMap<IChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();
// Pool discarded chunks for reuse (can safely be cleared by another thread)
private static final ConcurrentLinkedQueue<IChunk> CHUNK_POOL = new ConcurrentLinkedQueue<>();
public void returnToPool(final IChunk chunk) {
CHUNK_POOL.add(chunk);
}
@Override
public <T extends Future<T>> T submit(final IChunk<T> chunk) {
if (lastChunk == chunk) {
lastPair = Long.MAX_VALUE;
lastChunk = null;
}
final long index = MathMan.pairInt(chunk.getX(), chunk.getZ());
chunks.remove(index, chunk);
return submitUnchecked(chunk);
}
/**
* Submit without first checking that it has been removed from the chunk map
* @param chunk
* @param <T>
* @return
*/
private <T extends Future<T>> T submitUnchecked(final IChunk<T> chunk) {
if (chunk.isEmpty()) {
CHUNK_POOL.add(chunk);
return (T) (Future) Futures.immediateFuture(null);
}
if (Fawe.isMainThread()) {
return chunk.call();
}
return Fawe.get().getQueueHandler().submit(chunk);
}
@Override
public synchronized boolean trim(final boolean aggressive) {
// TODO trim individial chunk sections
CHUNK_POOL.clear();
if (Thread.currentThread() == currentThread) {
lastChunk = null;
lastPair = Long.MAX_VALUE;
return chunks.isEmpty();
}
if (!submissions.isEmpty()) {
if (aggressive) {
pollSubmissions(0, aggressive);
} else {
pollSubmissions(Settings.IMP.QUEUE.PARALLEL_THREADS, aggressive);
}
}
synchronized (this) {
return currentThread == null;
}
}
/**
* Get a new IChunk from either the pool, or create a new one<br>
* + Initialize it at the coordinates
* @param X
* @param Z
* @return IChunk
*/
private IChunk poolOrCreate(final int X, final int Z) {
IChunk next = CHUNK_POOL.poll();
if (next == null) {
next = create(false);
}
next.init(this, X, Z);
return next;
}
@Override
public final IChunk getCachedChunk(final int X, final int Z) {
final long pair = (((long) X) << 32) | (Z & 0xffffffffL);
if (pair == lastPair) {
return lastChunk;
}
IChunk chunk = chunks.get(pair);
if (chunk instanceof ReferenceChunk) {
chunk = ((ReferenceChunk) (chunk)).getParent();
}
if (chunk != null) {
lastPair = pair;
lastChunk = chunk;
}
if (chunk != null) return chunk;
checkThread();
final int size = chunks.size();
final boolean lowMem = MemUtil.isMemoryLimited();
if (lowMem || size > Settings.IMP.QUEUE.TARGET_SIZE) {
chunk = chunks.removeFirst();
final Future future = submitUnchecked(chunk);
if (future != null && !future.isDone()) {
final int targetSize;
if (lowMem) {
targetSize = Settings.IMP.QUEUE.PARALLEL_THREADS;
} else {
targetSize = Settings.IMP.QUEUE.TARGET_SIZE;
}
pollSubmissions(targetSize, true);
submissions.add(future);
}
}
chunk = poolOrCreate(X, Z);
chunk = wrap(chunk);
chunks.put(pair, chunk);
lastPair = pair;
lastChunk = chunk;
return chunk;
}
private void pollSubmissions(final int targetSize, final boolean aggressive) {
final int overflow = submissions.size() - targetSize;
if (aggressive) {
for (int i = 0; i < overflow; i++) {
Future first = submissions.poll();
try {
while ((first = (Future) first.get()) != null) ;
} catch (final InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
} else {
for (int i = 0; i < overflow; i++) {
Future next = submissions.peek();
while (next != null) {
if (next.isDone()) {
try {
next = (Future) next.get();
} catch (final InterruptedException | ExecutionException e) {
e.printStackTrace();
}
} else {
return;
}
}
submissions.poll();
}
}
}
@Override
public synchronized void flush() {
checkThread();
if (!chunks.isEmpty()) {
if (MemUtil.isMemoryLimited()) {
for (final IChunk chunk : chunks.values()) {
final Future future = submitUnchecked(chunk);
if (future != null && !future.isDone()) {
pollSubmissions(Settings.IMP.QUEUE.PARALLEL_THREADS, true);
submissions.add(future);
}
}
} else {
for (final IChunk chunk : chunks.values()) {
final Future future = submitUnchecked(chunk);
if (future != null && !future.isDone()) {
submissions.add(future);
}
}
}
chunks.clear();
}
pollSubmissions(0, true);
reset();
}
}

Datei anzeigen

@ -0,0 +1,72 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.Trimable;
import com.sk89q.worldedit.world.World;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import java.lang.ref.WeakReference;
import java.util.function.Supplier;
/**
* IGetBlocks may be cached by the WorldChunkCache so that it can be used between multiple IQueueExtents
* - avoids conversion between palette and raw data on every block get
*/
public class WorldChunkCache implements Trimable {
protected final Long2ObjectLinkedOpenHashMap<WeakReference<IChunkGet>> getCache;
private final World world;
protected WorldChunkCache(final World world) {
this.world = world;
this.getCache = new Long2ObjectLinkedOpenHashMap<>();
}
public World getWorld() {
return world;
}
public synchronized int size() {
return getCache.size();
}
/**
* Get or create the IGetBlocks
* @param index chunk index {@link com.boydti.fawe.util.MathMan#pairInt(int, int)}
* @param provider used to create if it isn't already cached
* @return cached IGetBlocks
*/
public synchronized IChunkGet get(final long index, final Supplier<IChunkGet> provider) {
final WeakReference<IChunkGet> ref = getCache.get(index);
if (ref != null) {
final IChunkGet blocks = ref.get();
if (blocks != null) return blocks;
}
final IChunkGet blocks = provider.get();
getCache.put(index, new WeakReference<>(blocks));
return blocks;
}
@Override
public synchronized boolean trim(final boolean aggressive) {
boolean result = true;
if (!getCache.isEmpty()) {
final ObjectIterator<Long2ObjectMap.Entry<WeakReference<IChunkGet>>> iter = getCache.long2ObjectEntrySet().fastIterator();
while (iter.hasNext()) {
final Long2ObjectMap.Entry<WeakReference<IChunkGet>> entry = iter.next();
final WeakReference<IChunkGet> value = entry.getValue();
final IChunkGet igb = value.get();
if (igb == null) iter.remove();
else {
result = false;
if (!aggressive) return result;
synchronized (igb) {
igb.trim(aggressive);
}
}
}
}
return result;
}
}

Datei anzeigen

@ -0,0 +1,114 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IBlocks;
import com.boydti.fawe.beta.IChunkSet;
public class CharBlocks implements IBlocks {
public final char[][] blocks;
public final Section[] sections;
public CharBlocks(CharBlocks other) {
this.blocks = other.blocks;
this.sections = other.sections;
}
public CharBlocks() {
blocks = new char[16][];
sections = new Section[16];
for (int i = 0; i < 16; i++) sections[i] = EMPTY;
}
@Override
public boolean trim(final boolean aggressive) {
boolean result = true;
for (int i = 0; i < 16; i++) {
if (sections[i] == EMPTY) {
blocks[i] = null;
} else {
result = false;
}
}
return result;
}
@Override
public IChunkSet reset() {
for (int i = 0; i < 16; i++) sections[i] = EMPTY;
return null;
}
public void reset(final int layer) {
sections[layer] = EMPTY;
}
public char[] load(final int layer) {
return new char[4096];
}
public char[] load(final int layer, final char[] data) {
for (int i = 0; i < 4096; i++) data[i] = 0;
return data;
}
@Override
public boolean hasSection(final int layer) {
return sections[layer] == FULL;
}
public char get(final int x, final int y, final int z) {
final int layer = y >> 4;
final int index = ((y & 15) << 8) | (z << 4) | (x & 15);
return sections[layer].get(this, layer, index);
}
public void set(final int x, final int y, final int z, final char value) {
final int layer = y >> 4;
final int index = ((y & 15) << 8) | (z << 4) | (x & 15);
set(layer, index, value);
}
public final char get(final int layer, final int index) {
return sections[layer].get(this, layer, index);
}
public final void set(final int layer, final int index, final char value) {
sections[layer].set(this, layer, index, value);
}
/*
Section
*/
public static abstract class Section {
public abstract char[] get(CharBlocks blocks, int layer);
public final char get(final CharBlocks blocks, final int layer, final int index) {
return get(blocks, layer)[index];
}
public final void set(final CharBlocks blocks, final int layer, final int index, final char value) {
get(blocks, layer)[index] = value;
}
}
public static final Section EMPTY = new Section() {
@Override
public final char[] get(final CharBlocks blocks, final int layer) {
blocks.sections[layer] = FULL;
char[] arr = blocks.blocks[layer];
if (arr == null) {
arr = blocks.blocks[layer] = blocks.load(layer);
} else {
blocks.blocks[layer] = blocks.load(layer, arr);
}
return arr;
}
};
public static final Section FULL = new Section() {
@Override
public final char[] get(final CharBlocks blocks, final int layer) {
return blocks.blocks[layer];
}
};
}

Datei anzeigen

@ -0,0 +1,34 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
public abstract class CharGetBlocks extends CharBlocks implements IChunkGet {
@Override
public BaseBlock getFullBlock(final int x, final int y, final int z) {
return BlockTypes.states[get(x, y, z)].toBaseBlock();
}
@Override
public BlockState getBlock(final int x, final int y, final int z) {
return BlockTypes.states[get(x, y, z)];
}
@Override
public boolean trim(final boolean aggressive) {
for (int i = 0; i < 16; i++) {
sections[i] = EMPTY;
blocks[i] = null;
}
return true;
}
@Override
public IChunkSet reset() {
super.reset();
return null;
}
}

Datei anzeigen

@ -0,0 +1,124 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.util.MathMan;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class CharSetBlocks extends CharBlocks implements IChunkSet {
public BiomeType[] biomes;
public HashMap<Short, CompoundTag> tiles;
public HashSet<CompoundTag> entities;
public HashSet<UUID> entityRemoves;
public CharSetBlocks(CharBlocks other) {
super(other);
if (other instanceof CharSetBlocks) {
}
}
public CharSetBlocks() {
}
@Override
public char[] getArray(int layer) {
return sections[layer].get(this, layer);
}
@Override
public BiomeType[] getBiomes() {
return biomes;
}
@Override
public Map<Short, CompoundTag> getTiles() {
return tiles;
}
@Override
public Set<CompoundTag> getEntities() {
return entities;
}
@Override
public Set<UUID> getEntityRemoves() {
return entityRemoves;
}
@Override
public boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
if (biomes == null) {
biomes = new BiomeType[256];
}
biomes[x + (z << 4)] = biome;
return true;
}
@Override
public BlockState getBlock(int x, int y, int z) {
return BlockTypes.states[get(x, y, z)];
}
@Override
public boolean setBlock(final int x, final int y, final int z, final BlockStateHolder holder) {
set(x, y, z, holder.getOrdinalChar());
return true;
}
@Override
public void setTile(final int x, final int y, final int z, final CompoundTag tile) {
if (tiles == null) {
tiles = new HashMap<>();
}
final short pair = MathMan.tripleBlockCoord(x, y, z);
tiles.put(pair, tile);
}
@Override
public void setEntity(final CompoundTag tag) {
if (entities == null) {
entities = new HashSet<>();
}
entities.add(tag);
}
@Override
public void removeEntity(final UUID uuid) {
if (entityRemoves == null) {
entityRemoves = new HashSet<>();
}
entityRemoves.add(uuid);
}
@Override
public boolean isEmpty() {
if (biomes != null) return false;
for (int i = 0; i < 16; i++) {
if (hasSection(i)) {
return false;
}
}
return true;
}
@Override
public IChunkSet reset() {
biomes = null;
tiles = null;
entities = null;
entityRemoves = null;
super.reset();
return null;
}
}

Datei anzeigen

@ -0,0 +1,311 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlockMask;
import com.boydti.fawe.beta.Flood;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.beta.implementation.blocks.CharSetBlocks;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.function.Supplier;
/**
* Abstract IChunk class that implements basic get/set blocks
*/
public abstract class ChunkHolder implements IChunk, Supplier<IChunkGet> {
private IChunkGet get;
private IChunkSet set;
private IBlockDelegate delegate;
private IQueueExtent extent;
private int X,Z;
public ChunkHolder() {
this.delegate = NULL;
}
public ChunkHolder(final IBlockDelegate delegate) {
this.delegate = delegate;
}
@Override
public void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) {
// block.flood(get, set, mask, block, );
}
@Override
public void filterBlocks(final Filter filter, ChunkFilterBlock block, @Nullable Region region) {
final IChunkGet get = getOrCreateGet();
final IChunkSet set = getOrCreateSet();
try {
if (region != null) {
region.filter(this, filter, block, get, set);
} else {
block = block.init(X, Z, get);
for (int layer = 0; layer < 16; layer++) {
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
block.init(get, set, layer);
block.filter(filter);
}
}
} finally {
filter.finishChunk(this);
}
}
@Override
public boolean trim(final boolean aggressive) {
if (set != null) {
final boolean result = set.trim(aggressive);
if (result) {
delegate = NULL;
get = null;
set = null;
return true;
}
}
if (aggressive) {
get = null;
if (delegate == BOTH) {
delegate = SET;
} else if (delegate == GET) {
delegate = NULL;
}
} else {
get.trim(false);
}
return false;
}
@Override
public boolean isEmpty() {
return set == null || set.isEmpty();
}
public final IChunkGet getOrCreateGet() {
if (get == null) get = newGet();
return get;
}
public final IChunkSet getOrCreateSet() {
if (set == null) set = set();
return set;
}
public IChunkSet set() {
return new CharSetBlocks();
}
private IChunkGet newGet() {
if (extent instanceof SingleThreadQueueExtent) {
final WorldChunkCache cache = ((SingleThreadQueueExtent) extent).getCache();
return cache.get(MathMan.pairInt(X, Z), this);
}
return get();
}
@Override
public void init(final IQueueExtent extent, final int X, final int Z) {
this.extent = extent;
this.X = X;
this.Z = Z;
if (set != null) {
set.reset();
delegate = SET;
} else {
delegate = NULL;
}
get = null;
}
public IQueueExtent getExtent() {
return extent;
}
@Override
public int getX() {
return X;
}
@Override
public int getZ() {
return Z;
}
@Override
public boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
return delegate.setBiome(this, x, y, z, biome);
}
@Override
public boolean setBlock(final int x, final int y, final int z, final BlockStateHolder block) {
return delegate.setBlock(this, x, y, z, block);
}
@Override
public BiomeType getBiome(final int x, final int z) {
return delegate.getBiome(this, x, z);
}
@Override
public BlockState getBlock(final int x, final int y, final int z) {
return delegate.getBlock(this, x, y, z);
}
@Override
public BaseBlock getFullBlock(final int x, final int y, final int z) {
return delegate.getFullBlock(this, x, y, z);
}
public interface IBlockDelegate {
boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome);
boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder holder);
BiomeType getBiome(final ChunkHolder chunk, final int x, final int z);
BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z);
BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z);
}
public static final IBlockDelegate NULL = new IBlockDelegate() {
@Override
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
chunk.getOrCreateSet();
chunk.delegate = SET;
return chunk.setBiome(x, y, z, biome);
}
@Override
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
chunk.getOrCreateSet();
chunk.delegate = SET;
return chunk.setBlock(x, y, z, block);
}
@Override
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
chunk.getOrCreateGet();
chunk.delegate = GET;
return chunk.getBiome(x, z);
}
@Override
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
chunk.getOrCreateGet();
chunk.delegate = GET;
return chunk.getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
chunk.getOrCreateGet();
chunk.delegate = GET;
return chunk.getFullBlock(x, y, z);
}
};
public static final IBlockDelegate GET = new IBlockDelegate() {
@Override
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
chunk.getOrCreateSet();
chunk.delegate = BOTH;
return chunk.setBiome(x, y, z, biome);
}
@Override
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
chunk.getOrCreateSet();
chunk.delegate = BOTH;
return chunk.setBlock(x, y, z, block);
}
@Override
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
return chunk.get.getBiomeType(x, z);
}
@Override
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
return chunk.get.getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
return chunk.get.getFullBlock(x, y, z);
}
};
public static final IBlockDelegate SET = new IBlockDelegate() {
@Override
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
return chunk.set.setBiome(x, y, z, biome);
}
@Override
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
return chunk.set.setBlock(x, y, z, block);
}
@Override
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
chunk.getOrCreateGet();
chunk.delegate = BOTH;
return chunk.getBiome(x, z);
}
@Override
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
chunk.getOrCreateGet();
chunk.delegate = BOTH;
return chunk.getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
chunk.getOrCreateGet();
chunk.delegate = BOTH;
return chunk.getFullBlock(x, y, z);
}
};
public static final IBlockDelegate BOTH = new IBlockDelegate() {
@Override
public boolean setBiome(final ChunkHolder chunk, final int x, final int y, final int z, final BiomeType biome) {
return chunk.set.setBiome(x, y, z, biome);
}
@Override
public boolean setBlock(final ChunkHolder chunk, final int x, final int y, final int z, final BlockStateHolder block) {
return chunk.set.setBlock(x, y, z, block);
}
@Override
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
return chunk.get.getBiomeType(x, z);
}
@Override
public BlockState getBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
return chunk.get.getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(final ChunkHolder chunk, final int x, final int y, final int z) {
return chunk.get.getFullBlock(x, y, z);
}
};
}

Datei anzeigen

@ -0,0 +1,33 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.ChunkFilterBlock;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.FilterBlockMask;
import com.boydti.fawe.beta.Flood;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IDelegateChunk;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable;
/**
* Implementation of IDelegateChunk
* @param <T>
*/
public class DelegateChunk<T extends IChunk> implements IDelegateChunk {
private T parent;
public DelegateChunk(final T parent) {
this.parent = parent;
}
public final T getParent() {
return parent;
}
public final void setParent(final T parent) {
this.parent = parent;
}
}

Datei anzeigen

@ -0,0 +1,31 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.IChunk;
/**
* Used by {@link ReferenceChunk} to allow the chunk to be garbage collected
* - When the object is finalized, add it to the queue
*/
public class FinalizedChunk extends DelegateChunk {
private final IQueueExtent queueExtent;
public FinalizedChunk(final IChunk parent, final IQueueExtent queueExtent) {
super(parent);
this.queueExtent = queueExtent;
}
/**
* Submit the chunk to the queue
* @throws Throwable
*/
@Override
protected void finalize() throws Throwable {
if (getParent() != null) {
// TODO apply safely
// apply();
setParent(null);
}
super.finalize();
}
}

Datei anzeigen

@ -0,0 +1,28 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IDelegateChunk;
import com.boydti.fawe.beta.IQueueExtent;
import java.lang.ref.Reference;
/**
* An IChunk may be wrapped by a ReferenceChunk if there is low memory<br>
* A reference chunk stores a reference (for garbage collection purposes)<br>
* - If it is garbage collected, the {@link FinalizedChunk} logic is run
*/
public abstract class ReferenceChunk implements IDelegateChunk {
private final Reference<FinalizedChunk> ref;
public ReferenceChunk(final IChunk parent, final IQueueExtent queueExtent) {
this.ref = toRef(new FinalizedChunk(parent, queueExtent));
}
protected abstract Reference<FinalizedChunk> toRef(FinalizedChunk parent);
@Override
public IChunk getParent() {
final FinalizedChunk finalized = ref.get();
return finalized != null ? finalized.getParent() : null;
}
}

Datei anzeigen

@ -0,0 +1,22 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IQueueExtent;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
/**
* Soft reference implementation of {@link ReferenceChunk}
*/
public class SoftChunk extends ReferenceChunk {
public SoftChunk(final IChunk parent, final IQueueExtent queueExtent) {
super(parent, queueExtent);
}
@Override
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
return new SoftReference<>(parent);
}
}

Datei anzeigen

@ -0,0 +1,21 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IQueueExtent;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
/**
* Weak reference implementation of {@link ReferenceChunk}
*/
public class WeakChunk extends ReferenceChunk {
public WeakChunk(final IChunk parent, final IQueueExtent queueExtent) {
super(parent, queueExtent);
}
@Override
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
return new WeakReference<>(parent);
}
}

Datei anzeigen

@ -2,6 +2,7 @@ package com.boydti.fawe.command;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI; import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.beta.SingleFilterBlock;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Commands; import com.boydti.fawe.config.Commands;
import com.boydti.fawe.jnbt.anvil.HeightMapMCAGenerator; import com.boydti.fawe.jnbt.anvil.HeightMapMCAGenerator;
@ -9,7 +10,6 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.clipboard.MultiClipboardHolder; import com.boydti.fawe.object.clipboard.MultiClipboardHolder;
import com.boydti.fawe.object.pattern.PatternExtent;
import com.boydti.fawe.util.CleanTextureUtil; import com.boydti.fawe.util.CleanTextureUtil;
import com.boydti.fawe.util.FilteredTextureUtil; import com.boydti.fawe.util.FilteredTextureUtil;
import com.boydti.fawe.util.ImgurUtility; import com.boydti.fawe.util.ImgurUtility;
@ -37,7 +37,6 @@ import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
@ -70,7 +69,6 @@ import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import static com.boydti.fawe.util.image.ImageUtil.load; import static com.boydti.fawe.util.image.ImageUtil.load;
@ -419,9 +417,7 @@ public class CFICommands extends MethodCommands {
} }
default: { default: {
blocks = new HashSet<>(); blocks = new HashSet<>();
BlockPattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); SingleFilterBlock extent = new SingleFilterBlock();
PatternExtent extent = new PatternExtent(pattern);
ParserContext parserContext = new ParserContext(); ParserContext parserContext = new ParserContext();
parserContext.setActor(player); parserContext.setActor(player);
parserContext.setWorld(player.getWorld()); parserContext.setWorld(player.getWorld());
@ -432,9 +428,10 @@ public class CFICommands extends MethodCommands {
TextureUtil tu = Fawe.get().getTextureUtil(); TextureUtil tu = Fawe.get().getTextureUtil();
for (int typeId : tu.getValidBlockIds()) { for (int typeId : tu.getValidBlockIds()) {
BlockType type = BlockTypes.get(typeId); BlockType type = BlockTypes.get(typeId);
BlockStateHolder block = type.getDefaultState(); extent.init(0, 0, 0, type.getDefaultState().toBaseBlock());
pattern.setBlock(block); if (mask.test(extent)) {
if (mask.test(BlockVector3.ZERO)) blocks.add(type); blocks.add(type);
}
} }
break; break;
} }

Datei anzeigen

@ -257,8 +257,8 @@ public class Settings extends Config {
public static class QUEUE { public static class QUEUE {
@Comment({ @Comment({
"This should equal the number of processors you have", "This should equal the number of processors you have",
" - Set this to 1 if you need reliable `/timings`"
}) })
@Final
public int PARALLEL_THREADS = Math.max(1, Runtime.getRuntime().availableProcessors()); public int PARALLEL_THREADS = Math.max(1, Runtime.getRuntime().availableProcessors());
@Create @Create
public static PROGRESS PROGRESS; public static PROGRESS PROGRESS;

Datei anzeigen

@ -42,7 +42,7 @@ public class NBTStreamer {
try { try {
is.readNamedTagLazy(node -> { is.readNamedTagLazy(node -> {
if (readers.isEmpty()) { if (readers.isEmpty()) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MANUAL); throw FaweException.MANUAL;
} }
return readers.remove(node); return readers.remove(node);
}); });

Datei anzeigen

@ -14,7 +14,6 @@ public final class BitArray4096 {
maxEntryValue = (1 << bitsPerEntry) - 1; maxEntryValue = (1 << bitsPerEntry) - 1;
this.longLen = (this.bitsPerEntry * 4096) >> 6; this.longLen = (this.bitsPerEntry * 4096) >> 6;
if (buffer.length < longLen) { if (buffer.length < longLen) {
System.out.println("Invalid buffer " + buffer.length + " | " + longLen);
this.data = new long[longLen]; this.data = new long[longLen];
} else { } else {
this.data = buffer; this.data = buffer;
@ -159,4 +158,38 @@ public final class BitArray4096 {
} }
return buffer; return buffer;
} }
public final char[] toRaw(char[] buffer) {
final long[] data = this.data;
final int dataLength = longLen;
final int bitsPerEntry = this.bitsPerEntry;
final int maxEntryValue = this.maxEntryValue;
final int maxSeqLocIndex = this.maxSeqLocIndex;
int localStart = 0;
char lastVal;
int arrI = 0;
long l;
for (int i = 0; i < dataLength; i++) {
l = data[i];
for (; localStart <= maxSeqLocIndex; localStart += bitsPerEntry) {
lastVal = (char) (l >>> localStart & maxEntryValue);
buffer[arrI++] = lastVal;
}
if (localStart < 64) {
if (i != dataLength - 1) {
lastVal = (char) (l >>> localStart);
localStart -= maxSeqLocIndex;
l = data[i + 1];
int localShift = bitsPerEntry - localStart;
lastVal |= l << localShift;
lastVal &= maxEntryValue;
buffer[arrI++] = lastVal;
}
} else {
localStart = 0;
}
}
return buffer;
}
} }

Datei anzeigen

@ -2,6 +2,12 @@ package com.boydti.fawe.jnbt.anvil;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.beta.ArrayFilterBlock;
import com.boydti.fawe.beta.DelegateFilter;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.SimpleFilterBlock;
import com.boydti.fawe.beta.filters.ArrayImageMask;
import com.boydti.fawe.example.SimpleIntFaweChunk; import com.boydti.fawe.example.SimpleIntFaweChunk;
import com.boydti.fawe.jnbt.anvil.HeightMapMCADrawer; import com.boydti.fawe.jnbt.anvil.HeightMapMCADrawer;
import com.boydti.fawe.jnbt.anvil.MCAChunk; import com.boydti.fawe.jnbt.anvil.MCAChunk;
@ -1023,7 +1029,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
@Override @Override
public BlockState getBlock(BlockVector3 position) { public BlockState getBlock(BlockVector3 position) {
return getLazyBlock(position); return getBlock(position.getX(), position.getY(), position.getZ());
} }
public BlockState getFloor(int x, int z) { public BlockState getFloor(int x, int z) {
@ -1046,12 +1052,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
} }
@Override @Override
public BlockState getLazyBlock(BlockVector3 position) { public BlockState getBlock(int x, int y, int z) {
return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ());
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return BlockState.getFromInternalId(getCombinedId4Data(x, y, z)); return BlockState.getFromInternalId(getCombinedId4Data(x, y, z));
} }

Datei anzeigen

@ -77,9 +77,6 @@ public class MCAChunk extends FaweChunk<Void> {
} }
public void write(NBTOutputStream nbtOut) throws IOException { public void write(NBTOutputStream nbtOut) throws IOException {
nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND); nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND);
nbtOut.writeLazyCompoundTag("Level", out -> { nbtOut.writeLazyCompoundTag("Level", out -> {
out.writeNamedTag("V", (byte) 1); out.writeNamedTag("V", (byte) 1);

Datei anzeigen

@ -79,7 +79,7 @@ public class MCAFile {
this.queue = parent; this.queue = parent;
this.file = file; this.file = file;
if (!file.exists()) { if (!file.exists()) {
throw new FaweException.FaweChunkLoadException(); throw FaweException.CHUNK;
} }
String[] split = file.getName().split("\\."); String[] split = file.getName().split("\\.");
X = Integer.parseInt(split[1]); X = Integer.parseInt(split[1]);

Datei anzeigen

@ -104,7 +104,7 @@ public class MCAWorld implements SimpleWorld {
@Override @Override
public BlockState getBlock(BlockVector3 position) { public BlockState getBlock(BlockVector3 position) {
return extent.getLazyBlock(position); return extent.getBlock(position);
} }
@Override @Override

Datei anzeigen

@ -149,7 +149,7 @@ public class CavesGen extends GenBase {
for (int local_z = i3; (!waterFound) && (local_z < i4); local_z++) { for (int local_z = i3; (!waterFound) && (local_z < i4); local_z++) {
for (int local_y = i2 + 1; (!waterFound) && (local_y >= i1 - 1); local_y--) { for (int local_y = i2 + 1; (!waterFound) && (local_y >= i1 - 1); local_y--) {
if (local_y < 255) { if (local_y < 255) {
BlockStateHolder material = chunk.getLazyBlock(bx + local_x, local_y, bz + local_z); BlockStateHolder material = chunk.getBlock(bx + local_x, local_y, bz + local_z);
if (material.getBlockType() == BlockTypes.WATER) { if (material.getBlockType() == BlockTypes.WATER) {
waterFound = true; waterFound = true;
} }
@ -173,8 +173,8 @@ public class CavesGen extends GenBase {
for (int local_y = i2; local_y > i1; local_y--) { for (int local_y = i2; local_y > i1; local_y--) {
double d11 = ((local_y - 1) + 0.5D - y) / d4; double d11 = ((local_y - 1) + 0.5D - y) / d4;
if ((d11 > -0.7D) && (d9 * d9 + d11 * d11 + d10 * d10 < 1.0D)) { if ((d11 > -0.7D) && (d9 * d9 + d11 * d11 + d10 * d10 < 1.0D)) {
BlockStateHolder material = chunk.getLazyBlock(bx + local_x, local_y, bz + local_z); BlockStateHolder material = chunk.getBlock(bx + local_x, local_y, bz + local_z);
BlockStateHolder materialAbove = chunk.getLazyBlock(bx + local_x, local_y + 1, bz + local_z); BlockStateHolder materialAbove = chunk.getBlock(bx + local_x, local_y + 1, bz + local_z);
BlockType blockType = material.getBlockType(); BlockType blockType = material.getBlockType();
switch (blockType.getInternalId()) { switch (blockType.getInternalId()) {
case BlockID.MYCELIUM: case BlockID.MYCELIUM:
@ -191,7 +191,7 @@ public class CavesGen extends GenBase {
// If grass was just deleted, try to // If grass was just deleted, try to
// move it down // move it down
if (grassFound) { if (grassFound) {
BlockStateHolder block = chunk.getLazyBlock(bx + local_x, local_y - 1, bz + local_z); BlockStateHolder block = chunk.getBlock(bx + local_x, local_y - 1, bz + local_z);
if (block.getBlockType() == BlockTypes.DIRT) { if (block.getBlockType() == BlockTypes.DIRT) {
chunk.setBlock(bx + local_x, local_y - 1, bz + local_z, BlockTypes.STONE.getDefaultState()); chunk.setBlock(bx + local_x, local_y - 1, bz + local_z, BlockTypes.STONE.getDefaultState());
} }

Datei anzeigen

@ -1,15 +1,14 @@
package com.boydti.fawe.object; package com.boydti.fawe.object;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.object.extent.ExtentHeightCacher; import com.boydti.fawe.object.extent.ExtentHeightCacher;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.AbstractPattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
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;
public class DataAnglePattern extends AbstractPattern { public class DataAnglePattern extends AbstractPattern {
public final double FACTOR; public final double FACTOR;
@ -24,7 +23,7 @@ public class DataAnglePattern extends AbstractPattern {
this.FACTOR = (1D / distance) * (1D / 255); this.FACTOR = (1D / distance) * (1D / 255);
} }
public int getSlope(BlockStateHolder block, BlockVector3 vector) { public int getSlope(BlockStateHolder block, BlockVector3 vector, Extent extent) {
int x = vector.getBlockX(); int x = vector.getBlockX();
int y = vector.getBlockY(); int y = vector.getBlockY();
int z = vector.getBlockZ(); int z = vector.getBlockZ();
@ -32,7 +31,6 @@ public class DataAnglePattern extends AbstractPattern {
return -1; return -1;
} }
int slope; int slope;
boolean aboveMin;
slope = Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z, y, 0, maxY)) * 7; slope = Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z, y, 0, maxY)) * 7;
slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x, z - distance, y, 0, maxY)) * 7; slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x, z - distance, y, 0, maxY)) * 7;
slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z - distance, y, 0, maxY)) * 5; slope += Math.abs(extent.getNearestSurfaceTerrainBlock(x + distance, z + distance, y, 0, maxY) - extent.getNearestSurfaceTerrainBlock(x - distance, z - distance, y, 0, maxY)) * 5;
@ -42,8 +40,8 @@ public class DataAnglePattern extends AbstractPattern {
@Override @Override
public BaseBlock apply(BlockVector3 position) { public BaseBlock apply(BlockVector3 position) {
BlockStateHolder block = extent.getBlock(position); BlockState block = extent.getBlock(position);
int slope = getSlope(block, position); int slope = getSlope(block, position, extent);
if (slope == -1) return block.toBaseBlock(); if (slope == -1) return block.toBaseBlock();
int data = (Math.min(slope, 255)) >> 4; int data = (Math.min(slope, 255)) >> 4;
return block.withPropertyId(data).toBaseBlock(); return block.withPropertyId(data).toBaseBlock();
@ -52,7 +50,7 @@ public class DataAnglePattern extends AbstractPattern {
@Override @Override
public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException {
BlockStateHolder block = extent.getBlock(getPosition); BlockStateHolder block = extent.getBlock(getPosition);
int slope = getSlope(block, getPosition); int slope = getSlope(block, getPosition, extent);
if (slope == -1) return false; if (slope == -1) return false;
int data = (Math.min(slope, 255)) >> 4; int data = (Math.min(slope, 255)) >> 4;
return extent.setBlock(setPosition, block.withPropertyId(data)); return extent.setBlock(setPosition, block.withPropertyId(data));

Datei anzeigen

@ -243,9 +243,9 @@ public abstract class FawePlayer<T> extends Metadatable {
Region[] allowed = WEManager.IMP.getMask(this, FaweMaskManager.MaskType.OWNER); Region[] allowed = WEManager.IMP.getMask(this, FaweMaskManager.MaskType.OWNER);
HashSet<Region> allowedSet = new HashSet<>(Arrays.asList(allowed)); HashSet<Region> allowedSet = new HashSet<>(Arrays.asList(allowed));
if (allowed.length == 0) { if (allowed.length == 0) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION); throw FaweException.NO_REGION;
} else if (!WEManager.IMP.regionContains(wrappedSelection, allowedSet)) { } else if (!WEManager.IMP.regionContains(wrappedSelection, allowedSet)) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); throw FaweException.OUTSIDE_REGION;
} }
} }

Datei anzeigen

@ -72,7 +72,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
} }
@Override @Override
default BlockState getLazyBlock(int x, int y, int z) { default BlockState getBlock(int x, int y, int z) {
int combinedId4Data = getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId()); int combinedId4Data = getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId());
try { try {
return BlockState.getFromInternalId(combinedId4Data); return BlockState.getFromInternalId(combinedId4Data);

Datei anzeigen

@ -29,7 +29,6 @@ public class HistoryExtent extends AbstractDelegateExtent {
private FaweChangeSet changeSet; private FaweChangeSet changeSet;
private final FaweQueue queue; private final FaweQueue queue;
private final EditSession session;
/** /**
* Create a new instance. * Create a new instance.
@ -37,12 +36,11 @@ public class HistoryExtent extends AbstractDelegateExtent {
* @param extent the extent * @param extent the extent
* @param changeSet the change set * @param changeSet the change set
*/ */
public HistoryExtent(final EditSession session, final Extent extent, final FaweChangeSet changeSet, FaweQueue queue) { public HistoryExtent(final Extent extent, final FaweChangeSet changeSet, FaweQueue queue) {
super(extent); super(extent);
checkNotNull(changeSet); checkNotNull(changeSet);
this.queue = queue; this.queue = queue;
this.changeSet = changeSet; this.changeSet = changeSet;
this.session = session;
} }
public FaweChangeSet getChangeSet() { public FaweChangeSet getChangeSet() {
@ -55,9 +53,9 @@ public class HistoryExtent extends AbstractDelegateExtent {
@Override @Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException { public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
BaseBlock previous = queue.getFullBlock(mutable.setComponents(x, y, z)).toBaseBlock(); BaseBlock previous = queue.getFullBlock(x, y, z);
if (previous.getInternalId() == block.getInternalId()) { if (previous.getInternalId() == block.getInternalId()) {
if (!previous.hasNbtData() && (block instanceof BaseBlock && !((BaseBlock)block).hasNbtData())) { if (!previous.hasNbtData() && (block instanceof BaseBlock && !block.hasNbtData())) {
return false; return false;
} }
} }

Datei anzeigen

@ -49,7 +49,6 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool {
} }
public Vector3 getTarget(Player player, boolean adjacent) { public Vector3 getTarget(Player player, boolean adjacent) {
Location target = null;
int range = this.range > -1 ? getRange() : MAX_RANGE; int range = this.range > -1 ? getRange() : MAX_RANGE;
if (adjacent) { if (adjacent) {
Location face = player.getBlockTraceFace(range, true); Location face = player.getBlockTraceFace(range, true);

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe.object.brush; package com.boydti.fawe.object.brush;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.collection.BlockVectorSet; import com.boydti.fawe.object.collection.BlockVectorSet;
import com.boydti.fawe.object.mask.AdjacentAnyMask; import com.boydti.fawe.object.mask.AdjacentAnyMask;
@ -7,6 +8,7 @@ import com.boydti.fawe.object.mask.RadiusMask;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.mask.SolidBlockMask;
@ -34,7 +36,7 @@ public class LayerBrush implements Brush {
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern ignore, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern ignore, double size) throws MaxChangedBlocksException {
final FaweQueue queue = editSession.getQueue(); final FaweQueue queue = editSession.getQueue();
final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockTypeMask(editSession, BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR)); final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockMask(editSession).add(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR));
final SolidBlockMask solid = new SolidBlockMask(editSession); final SolidBlockMask solid = new SolidBlockMask(editSession);
final RadiusMask radius = new RadiusMask(0, (int) size); final RadiusMask radius = new RadiusMask(0, (int) size);
visitor = new RecursiveVisitor(vector -> solid.test(vector) && radius.test(vector) && adjacent.test(vector), function -> true); visitor = new RecursiveVisitor(vector -> solid.test(vector) && radius.test(vector) && adjacent.test(vector), function -> true);
@ -42,8 +44,9 @@ public class LayerBrush implements Brush {
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
Operations.completeBlindly(visitor); Operations.completeBlindly(visitor);
BlockVectorSet visited = visitor.getVisited(); BlockVectorSet visited = visitor.getVisited();
BlockStateHolder firstPattern = layers[0]; visitor = new RecursiveVisitor(new Mask() {
visitor = new RecursiveVisitor((Mask) pos -> { @Override
public boolean test(BlockVector3 pos) {
int depth = visitor.getDepth() + 1; int depth = visitor.getDepth() + 1;
if (depth > 1) { if (depth > 1) {
boolean found = false; boolean found = false;
@ -66,6 +69,7 @@ public class LayerBrush implements Brush {
} }
} }
return !adjacent.test(pos); return !adjacent.test(pos);
}
}, pos -> { }, pos -> {
int depth = visitor.getDepth(); int depth = visitor.getDepth();
BlockStateHolder currentPattern = layers[depth]; BlockStateHolder currentPattern = layers[depth];

Datei anzeigen

@ -68,7 +68,7 @@ public class SplineBrush implements Brush, ResettableTool {
this.position = position; this.position = position;
if (newPos) { if (newPos) {
if (positionSets.size() >= MAX_POINTS) { if (positionSets.size() >= MAX_POINTS) {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); throw FaweException.MAX_CHECKS;
} }
final ArrayList<BlockVector3> points = new ArrayList<>(); final ArrayList<BlockVector3> points = new ArrayList<>();
if (size > 0) { if (size > 0) {

Datei anzeigen

@ -50,6 +50,7 @@ public class SurfaceSpline implements Brush {
n.setContinuity(continuity); n.setContinuity(continuity);
nodes.add(n); nodes.add(n);
} }
MutableBlockVector3 mutable = MutableBlockVector3.at(0, 0, 0);
interpol.setNodes(nodes); interpol.setNodes(nodes);
final double splinelength = interpol.arcLength(0, 1); final double splinelength = interpol.arcLength(0, 1);
for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) { for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
@ -60,7 +61,7 @@ public class SurfaceSpline implements Brush {
tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY); tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY);
if (tipy == -1) continue; if (tipy == -1) continue;
if (radius == 0) { if (radius == 0) {
BlockVector3 set = MutableBlockVector3.get(tipx, tipy, tipz); BlockVector3 set = mutable.setComponents(tipx, tipy, tipz);
try { try {
pattern.apply(editSession, set, set); pattern.apply(editSession, set, set);
} catch (WorldEditException e) { } catch (WorldEditException e) {

Datei anzeigen

@ -24,7 +24,12 @@ public interface VirtualWorld extends SimpleWorld, FaweQueue, Closeable {
@Override @Override
default BaseBlock getFullBlock(BlockVector3 position) { default BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position).toBaseBlock(); return getBlock(position).toBaseBlock();
}
@Override
default BaseBlock getFullBlock(int x, int y, int z) {
return getBlock(x, y, z).toBaseBlock();
} }
@Override @Override

Datei anzeigen

@ -40,7 +40,7 @@ public class VisualExtent extends AbstractDelegateExtent {
@Override @Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
BlockStateHolder previous = super.getLazyBlock(x, y, z); BlockStateHolder previous = super.getBlock(x, y, z);
int cx = x >> 4; int cx = x >> 4;
int cz = z >> 4; int cz = z >> 4;
long chunkPair = MathMan.pairInt(cx, cz); long chunkPair = MathMan.pairInt(cx, cz);

Datei anzeigen

@ -1,6 +1,5 @@
package com.boydti.fawe.object.changeset; package com.boydti.fawe.object.changeset;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@ -10,7 +9,6 @@ import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.extent.inventory.UnplaceableBlockException; import com.sk89q.worldedit.extent.inventory.UnplaceableBlockException;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
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.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -89,10 +87,10 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet {
try { try {
blockBag.fetchPlacedBlock(typeTo.getDefaultState()); blockBag.fetchPlacedBlock(typeTo.getDefaultState());
} catch (UnplaceableBlockException e) { } catch (UnplaceableBlockException e) {
throw new FaweException.FaweBlockBagException(); throw FaweException.BLOCK_BAG;
} catch (BlockBagException e) { } catch (BlockBagException e) {
missingBlocks[typeTo.getInternalId()]++; missingBlocks[typeTo.getInternalId()]++;
throw new FaweException.FaweBlockBagException(); throw FaweException.BLOCK_BAG;
} }
} }
if (mine) { if (mine) {

Datei anzeigen

@ -78,7 +78,7 @@ public class EmptyClipboard implements Clipboard {
} }
@Override @Override
public BlockState getLazyBlock(BlockVector3 position) { public BlockState getBlock(BlockVector3 position) {
return BlockTypes.AIR.getDefaultState(); return BlockTypes.AIR.getDefaultState();
} }

Datei anzeigen

@ -38,7 +38,8 @@ public class BlockVectorSet extends AbstractCollection<BlockVector3> implements
int newSize = count + size; int newSize = count + size;
if (newSize > index) { if (newSize > index) {
int localIndex = index - count; int localIndex = index - count;
BlockVector3 pos = mutable.setComponents(set.getIndex(localIndex)); BlockVector3 pos = set.getIndex(localIndex);
if (pos != null) {
int pair = entry.getIntKey(); int pair = entry.getIntKey();
int cx = MathMan.unpairX(pair); int cx = MathMan.unpairX(pair);
int cz = MathMan.unpairY(pair); int cz = MathMan.unpairY(pair);
@ -46,6 +47,7 @@ public class BlockVectorSet extends AbstractCollection<BlockVector3> implements
pos = pos.mutZ((cz << 11) + pos.getBlockZ()); pos = pos.mutZ((cz << 11) + pos.getBlockZ());
return pos; return pos;
} }
}
count += newSize; count += newSize;
} }
return null; return null;

Datei anzeigen

@ -244,9 +244,9 @@ public final class DifferentialArray<T> implements DifferentialCollection<T> {
return dataBytes; return dataBytes;
} }
// public char[] getCharArray() { public char[] getCharArray() {
// return dataChars; return dataChars;
// } }
public int[] getIntArray() { public int[] getIntArray() {
return dataInts; return dataInts;

Datei anzeigen

@ -0,0 +1,213 @@
package com.boydti.fawe.object.collection;
import com.boydti.fawe.object.FaweInputStream;
import com.boydti.fawe.object.FaweOutputStream;
import java.io.IOException;
import java.lang.reflect.Array;
/**
* Records changes made through the {@link #set(int, int, int, char)} method<br/>
* Changes are not recorded if you edit the raw data
*/
public final class DifferentialCharBlockBuffer implements DifferentialCollection<char[][][][][]> {
private final int width, length;
private final int t1, t2;
private char[][][][][] data;
private char[][][][][] changes;
public DifferentialCharBlockBuffer(int width, int length) {
this.width = width;
this.length = length;
this.t1 = (length + 15) >> 4;
this.t2 = (width + 15) >> 4;
}
@Override
public char[][][][][] get() {
return data;
}
@Override
public void flushChanges(FaweOutputStream out) throws IOException {
boolean modified = isModified();
out.writeBoolean(modified);
if (modified) {
writeArray(changes, 0, 0, out);
}
clearChanges();
}
private void writeArray(Object arr, int level, int index, FaweOutputStream out) throws IOException {
if (level == 4) {
if (arr != null) {
char[] level4 = (char[]) arr;
out.writeVarInt(level4.length);
for (char c : level4) {
out.writeChar(c);
}
} else {
out.writeVarInt(0);
}
} else {
int len = arr == null ? 0 : Array.getLength(arr);
out.writeVarInt(len);
for (int i = 0; i < len; i++) {
Object elem = Array.get(arr, i);
writeArray(elem, level + 1, i, out);
}
}
}
@Override
public void undoChanges(FaweInputStream in) throws IOException {
if (changes != null && changes.length != 0) throw new IllegalStateException("There are uncommitted changes, please flush first");
boolean modified = in.readBoolean();
if (modified) {
int len = in.readVarInt();
if (len == 0) {
data = null;
} else {
for (int i = 0; i < len; i++) {
readArray(data, i, 1, in);
}
}
}
clearChanges();
}
@Override
public void redoChanges(FaweInputStream in) throws IOException {
clearChanges();
throw new UnsupportedOperationException("Not implemented");
}
private void readArray(Object dataElem, int index, int level, FaweInputStream in) throws IOException {
int len = in.readVarInt();
if (level == 4) {
char[][] castedElem = (char[][]) dataElem;
if (len == 0) {
castedElem[index] = null;
} else {
char[] current = castedElem[index];
for (int i = 0; i < len; i++) {
current[i] = in.readChar();
}
}
} else {
if (len == 0) {
Array.set(dataElem, index, null);
} else {
Object nextElem = Array.get(dataElem, index);
for (int i = 0; i < len; i++) {
readArray(nextElem, i, level + 1, in);
}
}
}
}
public boolean isModified() {
return changes != null;
}
public void clearChanges() {
changes = null;
}
public void set(int x, int y, int z, char combined) {
if (combined == 0) combined = 1;
int localX = x & 15;
int localZ = z & 15;
int chunkX = x >> 4;
int chunkZ = z >> 4;
if (data == null) {
data = new char[t1][][][][];
changes = new char[0][][][][];
}
char[][][][] arr = data[chunkZ];
if (arr == null) {
arr = data[chunkZ] = new char[t2][][][];
}
char[][][] arr2 = arr[chunkX];
if (arr2 == null) {
arr2 = arr[chunkX] = new char[256][][];
}
char[][] yMap = arr2[y];
if (yMap == null) {
arr2[y] = yMap = new char[16][];
}
boolean newSection;
char current;
char[] zMap = yMap[localZ];
if (zMap == null) {
yMap[localZ] = zMap = new char[16];
if (changes == null) {
changes = new char[t1][][][][];
} else if (changes != null && changes.length != 0) {
initialChange(changes, chunkX, chunkZ, localX, localZ, y, (char) -combined);
}
} else {
if (changes == null || changes.length == 0) changes = new char[t1][][][][];
appendChange(changes, chunkX, chunkZ, localX, localZ, y, (char) (zMap[localX] - combined));
}
zMap[localX] = combined;
}
private void initialChange(char[][][][][] src, int chunkX, int chunkZ, int localX, int localZ, int y, char combined) {
char[][][][] arr = src[chunkZ];
if (arr == null) {
src[chunkZ] = new char[0][][][];
return;
} else if (arr.length == 0) return;
char[][][] arr2 = arr[chunkX];
if (arr2 == null) {
arr[chunkX] = new char[0][][];
return;
} else if (arr2.length == 0) return;
char[][] yMap = arr2[y];
if (yMap == null) {
arr2[y] = new char[0][];
return;
} else if (yMap.length == 0) return;
char[] zMap = yMap[localZ];
if (zMap == null) {
yMap[localZ] = new char[0];
return;
} else if (zMap.length == 0) return;
char current = zMap[localX];
zMap[localX] = combined;
}
private void appendChange(char[][][][][] src, int chunkX, int chunkZ, int localX, int localZ, int y, char combined) {
char[][][][] arr = src[chunkZ];
if (arr == null || arr.length == 0) {
arr = src[chunkZ] = new char[t2][][][];
}
char[][][] arr2 = arr[chunkX];
if (arr2 == null || arr2.length == 0) {
arr2 = arr[chunkX] = new char[256][][];
}
char[][] yMap = arr2[y];
if (yMap == null || yMap.length == 0) {
arr2[y] = yMap = new char[16][];
}
char[] zMap = yMap[localZ];
if (zMap == null || zMap.length == 0) {
yMap[localZ] = zMap = new char[16];
}
zMap[localX] = combined;
}
}

Datei anzeigen

@ -11,8 +11,7 @@ import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
public abstract class IterableThreadLocal<T> extends ThreadLocal<T> implements Iterable<T> { public abstract class IterableThreadLocal<T> extends ThreadLocal<T> implements Iterable<T> {
private ThreadLocal<T> flag; private final ConcurrentLinkedDeque<T> allValues = new ConcurrentLinkedDeque<>();
private ConcurrentLinkedDeque<T> allValues = new ConcurrentLinkedDeque<>();
public IterableThreadLocal() { public IterableThreadLocal() {
} }
@ -21,8 +20,10 @@ public abstract class IterableThreadLocal<T> extends ThreadLocal<T> implements I
protected final T initialValue() { protected final T initialValue() {
T value = init(); T value = init();
if (value != null) { if (value != null) {
synchronized (this) {
allValues.add(value); allValues.add(value);
} }
}
return value; return value;
} }
@ -36,7 +37,12 @@ public abstract class IterableThreadLocal<T> extends ThreadLocal<T> implements I
} }
public void clean() { public void clean() {
if (!allValues.isEmpty()) {
synchronized (this) {
IterableThreadLocal.clean(this); IterableThreadLocal.clean(this);
allValues.clear();
}
}
} }
public static void clean(ThreadLocal instance) { public static void clean(ThreadLocal instance) {

Datei anzeigen

@ -101,7 +101,7 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
this.offsetZ = z; this.offsetZ = z;
} }
public BlockVector3 getIndex(int getIndex) { protected BlockVector3 getIndex(int getIndex) {
int size = size(); int size = size();
if (getIndex > size) { if (getIndex > size) {
return null; return null;

Datei anzeigen

@ -3,6 +3,17 @@ package com.boydti.fawe.object.exception;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
public class FaweException extends RuntimeException { public class FaweException extends RuntimeException {
public static final FaweChunkLoadException CHUNK = new FaweChunkLoadException();
public static final FaweBlockBagException BLOCK_BAG = new FaweBlockBagException();
public static final FaweException MANUAL = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MANUAL);
public static final FaweException NO_REGION = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION);
public static final FaweException OUTSIDE_REGION = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
public static final FaweException MAX_CHECKS = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS);
public static final FaweException MAX_CHANGES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES);
public static final FaweException LOW_MEMORY = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY);
public static final FaweException MAX_ENTITIES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_ENTITIES);
public static final FaweException MAX_TILES = new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_TILES);
private final BBC message; private final BBC message;
public FaweException(BBC reason) { public FaweException(BBC reason) {
@ -42,7 +53,7 @@ public class FaweException extends RuntimeException {
} }
/** /**
* Faster exception throwing if you don't fill the stacktrace * Faster exception throwing/handling if you don't fill the stacktrace
* *
* @return * @return
*/ */

Datei anzeigen

@ -52,17 +52,12 @@ public class BlockTranslateExtent extends AbstractDelegateExtent {
@Override @Override
public BlockState getBlock(BlockVector3 location) { public BlockState getBlock(BlockVector3 location) {
return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()); return getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
} }
@Override @Override
public BlockState getLazyBlock(BlockVector3 location) { public BlockState getBlock(int x, int y, int z) {
return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()); return super.getBlock(x + dx, y + dy, z + dz);
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return super.getLazyBlock(x + dx, y + dy, z + dz);
} }
@Override @Override

Datei anzeigen

@ -126,12 +126,12 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
} }
@Override @Override
public BlockState getLazyBlock(BlockVector3 location) { public BlockState getBlock(BlockVector3 location) {
return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()); return getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
} }
@Override @Override
public BlockState getLazyBlock(int x, int y, int z) { public BlockState getBlock(int x, int y, int z) {
int combinedId4Data = queue.getCombinedId4Data(x, y, z, 0); int combinedId4Data = queue.getCombinedId4Data(x, y, z, 0);
BlockType type = BlockTypes.getFromStateId(combinedId4Data); BlockType type = BlockTypes.getFromStateId(combinedId4Data);
return type.withStateId(combinedId4Data); return type.withStateId(combinedId4Data);
@ -161,11 +161,6 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
return world.getEntities(region); return world.getEntities(region);
} }
@Override
public BlockState getBlock(final BlockVector3 position) {
return this.getLazyBlock(position);
}
@Override @Override
public boolean setBiome(final BlockVector2 position, final BiomeType biome) { public boolean setBiome(final BlockVector2 position, final BiomeType biome) {
queue.setBiome(position.getBlockX(), position.getBlockZ(), biome); queue.setBiome(position.getBlockX(), position.getBlockZ(), biome);

Datei anzeigen

@ -2,6 +2,7 @@ package com.boydti.fawe.object.extent;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.WEManager;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
@ -56,44 +57,22 @@ public abstract class FaweRegionExtent extends ResettableExtent {
return contains(p.getBlockX(), p.getBlockZ()); return contains(p.getBlockX(), p.getBlockZ());
} }
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (!contains(location)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return false;
}
return super.setBlock(location, block);
}
@Override @Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException { public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
if (!contains(x, y, z)) { if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return false; return false;
} }
return super.setBlock(x, y, z, block); return super.setBlock(x, y, z, block);
} }
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
if (!contains(position)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return false;
}
return super.setBiome(position, biome);
}
@Override @Override
public boolean setBiome(int x, int y, int z, BiomeType biome) { public boolean setBiome(int x, int y, int z, BiomeType biome) {
if (!contains(x, y, z)) { if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return false; return false;
} }
@ -104,18 +83,29 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public BiomeType getBiome(BlockVector2 position) { public BiomeType getBiome(BlockVector2 position) {
if (!contains(position)) { if (!contains(position)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return null; return null;
} }
return super.getBiome(position); return super.getBiome(position);
} }
@Override
public BiomeType getBiomeType(int x, int z) {
if (!contains(x, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
}
return null;
}
return super.getBiomeType(x, z);
}
@Override @Override
public BaseBlock getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
if (!contains(position)) { if (!contains(position)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return BlockTypes.AIR.getDefaultState().toBaseBlock(); return BlockTypes.AIR.getDefaultState().toBaseBlock();
} }
@ -126,40 +116,18 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public BlockState getBlock(BlockVector3 position) { public BlockState getBlock(BlockVector3 position) {
if (!contains(position)) { if (!contains(position)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return BlockTypes.AIR.getDefaultState(); return BlockTypes.AIR.getDefaultState();
} }
return super.getBlock(position); return super.getBlock(position);
} }
@Override
public BlockState getLazyBlock(BlockVector3 position) {
if (!contains(position)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return BlockTypes.AIR.getDefaultState();
}
return super.getLazyBlock(position);
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
}
return BlockTypes.AIR.getDefaultState();
}
return super.getLazyBlock(x, y, z);
}
@Override @Override
public int getBlockLight(int x, int y, int z) { public int getBlockLight(int x, int y, int z) {
if (!contains(x, y, z)) { if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return 0; return 0;
} }
@ -170,7 +138,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public int getBrightness(int x, int y, int z) { public int getBrightness(int x, int y, int z) {
if (!contains(x, y, z)) { if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return 0; return 0;
} }
@ -181,7 +149,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public int getLight(int x, int y, int z) { public int getLight(int x, int y, int z) {
if (!contains(x, y, z)) { if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return 0; return 0;
} }
@ -192,7 +160,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public int getOpacity(int x, int y, int z) { public int getOpacity(int x, int y, int z) {
if (!contains(x, y, z)) { if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return 0; return 0;
} }
@ -203,7 +171,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public int getSkyLight(int x, int y, int z) { public int getSkyLight(int x, int y, int z) {
if (!contains(x, y, z)) { if (!contains(x, y, z)) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return 0; return 0;
} }
@ -215,7 +183,7 @@ public abstract class FaweRegionExtent extends ResettableExtent {
public Entity createEntity(Location location, BaseEntity entity) { public Entity createEntity(Location location, BaseEntity entity) {
if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) { if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
if (!limit.MAX_FAILS()) { if (!limit.MAX_FAILS()) {
WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); WEManager.IMP.cancelEditSafe(this, FaweException.OUTSIDE_REGION);
} }
return null; return null;
} }

Datei anzeigen

@ -2,6 +2,7 @@ package com.boydti.fawe.object.extent;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.MemUtil; import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.Perm; import com.boydti.fawe.util.Perm;
import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.WEManager;
@ -30,7 +31,7 @@ public class MemoryCheckingExtent extends AbstractDelegateExtent {
BBC.WORLDEDIT_OOM_ADMIN.send(this.player); BBC.WORLDEDIT_OOM_ADMIN.send(this.player);
} }
} }
WEManager.IMP.cancelEdit(this, BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY); WEManager.IMP.cancelEdit(this, FaweException.LOW_MEMORY);
return false; return false;
} }
return true; return true;

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen