Dieser Commit ist enthalten in:
Jesse Boyd 2019-04-29 01:44:59 +10:00
Ursprung 6adf0e6435
Commit 57b5be84f4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
45 geänderte Dateien mit 1317 neuen und 870 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,46 @@
package com.boydti.fawe.bukkit.beta;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IGetBlocks;
import com.boydti.fawe.beta.implementation.blocks.CharSetBlocks;
import com.boydti.fawe.beta.implementation.holder.ChunkHolder;
public class BukkitChunkHolder extends ChunkHolder<Boolean, BukkitQueue> {
@Override
public void init(final BukkitQueue extent, final int X, final int Z) {
super.init(extent, X, Z);
}
@Override
public IGetBlocks get() {
BukkitQueue extent = getExtent();
return null;
}
@Override
public Boolean apply() {
BukkitGetBlocks get = (BukkitGetBlocks) cachedGet();
CharSetBlocks set = (CharSetBlocks) cachedSet();
// - getBlocks
// - set lock
// - synchronize on chunk object
// - verify section is same object as chunk's section
// - merge with setblocks
// - set section
// - verify chunk is same
// - verify section is same
// - Otherwise repeat steps on main thread
// - set status to needs relighting
// - mark as dirty
// - skip verification if main thread
throw new UnsupportedOperationException("Not implemented");
// return true;
}
@Override
public void filter(final Filter filter) {
// for each block
// filter.applyBlock(block)
throw new UnsupportedOperationException("Not implemented");
}
}

Datei anzeigen

@ -0,0 +1,37 @@
package com.boydti.fawe.bukkit.beta;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.ISetBlocks;
import com.boydti.fawe.beta.implementation.holder.ChunkHolder;
public class BukkitFullChunk extends ChunkHolder {
public BukkitFullChunk() {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public void init(IQueueExtent extent, int X, int Z) {
}
@Override
public Object apply() {
return null;
}
@Override
public void filter(Filter filter) {
}
@Override
public Object get() {
return null;
}
@Override
public ISetBlocks set() {
return null;
}
}

Datei anzeigen

@ -0,0 +1,8 @@
package com.boydti.fawe.bukkit.beta;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import net.minecraft.server.v1_13_R2.ChunkSection;
public class BukkitGetBlocks extends CharGetBlocks {
private ChunkSection[] sections;
}

Datei anzeigen

@ -0,0 +1,32 @@
package com.boydti.fawe.bukkit.beta;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.object.collection.IterableThreadLocal;
import com.sk89q.worldedit.world.World;
public class BukkitQueue extends SingleThreadQueueExtent {
@Override
public synchronized void init(WorldChunkCache cache) {
World world = cache.getWorld();
super.init(cache);
}
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) {
return FULL_CHUNKS.get();
} else {
return new BukkitChunkHolder();
}
}
}

Datei anzeigen

@ -81,15 +81,15 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
* @param x
* @param z
*/
public BukkitChunk_1_13(FaweQueue parent, int x, int z) {
public BukkitChunk_1_13(final FaweQueue parent, final int x, final int z) {
super(parent, x, z);
}
public BukkitChunk_1_13(FaweQueue parent, int x, int z, int[][] ids, short[] count, short[] air) {
public BukkitChunk_1_13(final FaweQueue parent, final int x, final int z, final int[][] ids, final short[] count, final short[] air) {
super(parent, x, z, ids, count, air);
}
public void storeBiomes(BiomeBase[] biomes) {
public void storeBiomes(final BiomeBase[] biomes) {
if (biomes != null) {
if (this.biomes == null) {
this.biomes = new BiomeType[256];
@ -111,33 +111,33 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
@Override
public int[] getIdArray(int layer) {
public int[] getIdArray(final int layer) {
if (this.setBlocks[layer] == null && this.sectionPalettes != null) {
ChunkSection section = this.sectionPalettes[layer];
final ChunkSection section = this.sectionPalettes[layer];
int[] idsArray = this.setBlocks[layer];
if (section != null && idsArray == null) {
this.setBlocks[layer] = idsArray = new int[4096];
if (!section.a()) {
try {
DataPaletteBlock<IBlockData> blocks = section.getBlocks();
DataBits bits = (DataBits) BukkitQueue_1_13.fieldBits.get(blocks);
DataPalette<IBlockData> palette = (DataPalette<IBlockData>) BukkitQueue_1_13.fieldPalette.get(blocks);
final DataPaletteBlock<IBlockData> blocks = section.getBlocks();
final DataBits bits = (DataBits) BukkitQueue_1_13.fieldBits.get(blocks);
final DataPalette<IBlockData> palette = (DataPalette<IBlockData>) BukkitQueue_1_13.fieldPalette.get(blocks);
long[] raw = bits.a();
int bitsPerEntry = bits.c();
final long[] raw = bits.a();
final int bitsPerEntry = bits.c();
new BitArray4096(raw, bitsPerEntry).toRaw(idsArray);
IBlockData defaultBlock = (IBlockData) BukkitQueue_1_13.fieldDefaultBlock.get(blocks);
final IBlockData defaultBlock = (IBlockData) BukkitQueue_1_13.fieldDefaultBlock.get(blocks);
// TODO optimize away palette.a
for (int i = 0; i < 4096; i++) {
IBlockData ibd = palette.a(idsArray[i]);
if (ibd == null) {
ibd = defaultBlock;
}
int ordinal = ((Spigot_v1_13_R2) getAdapter()).adaptToInt(ibd);
final int ordinal = ((Spigot_v1_13_R2) getAdapter()).adaptToInt(ibd);
idsArray[i] = BlockTypes.states[ordinal].getInternalId();
}
} catch (IllegalAccessException e) {
} catch (final IllegalAccessException e) {
e.printStackTrace();
}
}
@ -146,23 +146,23 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
return this.setBlocks[layer];
}
public boolean storeTile(TileEntity tile, BlockPosition pos) {
CompoundTag nativeTag = getParent().getTag(tile);
public boolean storeTile(final TileEntity tile, final BlockPosition pos) {
final CompoundTag nativeTag = getParent().getTag(tile);
setTile(pos.getX() & 15, pos.getY(), pos.getZ() & 15, nativeTag);
return true;
}
public boolean storeEntity(Entity ent) throws InvocationTargetException, IllegalAccessException {
public boolean storeEntity(final Entity ent) throws InvocationTargetException, IllegalAccessException {
if (ent instanceof EntityPlayer || BukkitQueue_0.getAdapter() == null) {
return false;
}
EntityTypes<?> type = ent.P();
MinecraftKey id = EntityTypes.getName(type);
final EntityTypes<?> type = ent.P();
final MinecraftKey id = EntityTypes.getName(type);
if (id != null) {
NBTTagCompound tag = new NBTTagCompound();
final NBTTagCompound tag = new NBTTagCompound();
ent.save(tag); // readEntityIntoTag
CompoundTag nativeTag = (CompoundTag) BukkitQueue_0.toNative(tag);
Map<String, Tag> map = ReflectionUtils.getMap(nativeTag.getValue());
final CompoundTag nativeTag = (CompoundTag) BukkitQueue_0.toNative(tag);
final Map<String, Tag> map = ReflectionUtils.getMap(nativeTag.getValue());
map.put("Id", new StringTag(id.toString()));
setEntity(nativeTag);
return true;
@ -171,7 +171,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
}
public boolean storeSection(ChunkSection section, int layer) throws IllegalAccessException {
public boolean storeSection(final ChunkSection section, final int layer) throws IllegalAccessException {
if (sectionPalettes == null) {
// TODO optimize don't copy light
sectionPalettes = new ChunkSection[16];
@ -180,56 +180,56 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
return true;
}
public ChunkSection copy(ChunkSection current) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
ChunkSection newSection = new ChunkSection(current.getYPosition(), current.getSkyLightArray() != null);
public ChunkSection copy(final ChunkSection current) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
final ChunkSection newSection = new ChunkSection(current.getYPosition(), current.getSkyLightArray() != null);
// Copy light
NibbleArray skyLight = current.getSkyLightArray();
NibbleArray blockLight = current.getEmittedLightArray();
final NibbleArray skyLight = current.getSkyLightArray();
final NibbleArray blockLight = current.getEmittedLightArray();
NibbleArray newBlockLight = newSection.getEmittedLightArray();
NibbleArray newSkyLight = newSection.getSkyLightArray();
final NibbleArray newBlockLight = newSection.getEmittedLightArray();
final NibbleArray newSkyLight = newSection.getSkyLightArray();
byte[] newBlockBytes = newBlockLight.asBytes();
byte[] blockLightBytes = blockLight.asBytes();
final byte[] newBlockBytes = newBlockLight.asBytes();
final byte[] blockLightBytes = blockLight.asBytes();
for (int i = 0; i < 2048; i++) newBlockBytes[i] = blockLightBytes[i];
if (skyLight != null) {
byte[] newSkyBytes = newSkyLight.asBytes();
byte[] skyLightBytes = skyLight.asBytes();
final byte[] newSkyBytes = newSkyLight.asBytes();
final byte[] skyLightBytes = skyLight.asBytes();
for (int i = 0; i < 2048; i++) newSkyBytes[i] = skyLightBytes[i];
}
// Copy counters
Object nonEmptyBlockCount = BukkitQueue_1_13.fieldNonEmptyBlockCount.get(current);
final Object nonEmptyBlockCount = BukkitQueue_1_13.fieldNonEmptyBlockCount.get(current);
BukkitQueue_1_13.fieldNonEmptyBlockCount.set(newSection, nonEmptyBlockCount);
Object tickingBlockCount = BukkitQueue_1_13.fieldTickingBlockCount.get(current);
final Object tickingBlockCount = BukkitQueue_1_13.fieldTickingBlockCount.get(current);
BukkitQueue_1_13.fieldTickingBlockCount.set(newSection, tickingBlockCount);
Object liquidCount = BukkitQueue_1_13.fieldLiquidCount.get(current);
final Object liquidCount = BukkitQueue_1_13.fieldLiquidCount.get(current);
BukkitQueue_1_13.fieldLiquidCount.set(newSection, liquidCount);
// Copy blocks
DataPaletteBlock<IBlockData> blocks = current.getBlocks();
DataPaletteBlock<IBlockData> blocksCopy = copy(blocks);
final DataPaletteBlock<IBlockData> blocks = current.getBlocks();
final DataPaletteBlock<IBlockData> blocksCopy = copy(blocks);
BukkitQueue_1_13.fieldSection.set(newSection, blocksCopy);
return newSection;
}
public DataPaletteBlock<IBlockData> copy(DataPaletteBlock current) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
public DataPaletteBlock<IBlockData> copy(final DataPaletteBlock current) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
// Clone palette
DataPalette currentPalette = (DataPalette) BukkitQueue_1_13.fieldPalette.get(current);
DataPaletteBlock<IBlockData> paletteBlock = newDataPaletteBlock();
int size = BukkitQueue_1_13.fieldSize.getInt(current);
final DataPalette currentPalette = (DataPalette) BukkitQueue_1_13.fieldPalette.get(current);
final DataPaletteBlock<IBlockData> paletteBlock = newDataPaletteBlock();
final int size = BukkitQueue_1_13.fieldSize.getInt(current);
DataPalette<IBlockData> newPalette = currentPalette;
if (currentPalette instanceof DataPaletteHash) {
// TODO optimize resize
newPalette = new DataPaletteHash<>(Block.REGISTRY_ID, size, paletteBlock, GameProfileSerializer::d, GameProfileSerializer::a);
RegistryID<IBlockData> currReg = (RegistryID<IBlockData>) BukkitQueue_1_13.fieldHashBlocks.get(currentPalette);
RegistryID<IBlockData> newReg = (RegistryID<IBlockData>) BukkitQueue_1_13.fieldHashBlocks.get(newPalette);
int arrLen = 1 << size;
final RegistryID<IBlockData> currReg = (RegistryID<IBlockData>) BukkitQueue_1_13.fieldHashBlocks.get(currentPalette);
final RegistryID<IBlockData> newReg = (RegistryID<IBlockData>) BukkitQueue_1_13.fieldHashBlocks.get(newPalette);
final int arrLen = 1 << size;
System.arraycopy(fieldRegistryb.get(currReg), 0, fieldRegistryb.get(newReg), 0, arrLen);
System.arraycopy(fieldRegistryc.get(currReg), 0, fieldRegistryc.get(newReg), 0, arrLen);
System.arraycopy(fieldRegistryd.get(currReg), 0, fieldRegistryd.get(newReg), 0, arrLen);
@ -238,8 +238,8 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
} else if (currentPalette instanceof DataPaletteLinear) {
// TODO optimize resize
newPalette = new DataPaletteLinear<>(Block.REGISTRY_ID, size, paletteBlock, GameProfileSerializer::d);
Object[] currArray = ((Object[]) BukkitQueue_1_13.fieldLinearBlocks.get(currentPalette));
Object[] newArray = ((Object[]) BukkitQueue_1_13.fieldLinearBlocks.get(newPalette));
final Object[] currArray = ((Object[]) BukkitQueue_1_13.fieldLinearBlocks.get(currentPalette));
final Object[] newArray = ((Object[]) BukkitQueue_1_13.fieldLinearBlocks.get(newPalette));
BukkitQueue_1_13.fieldLinearIndex.set(newPalette, BukkitQueue_1_13.fieldLinearIndex.get(currentPalette));
for (int i = 0; i < newArray.length; i++) newArray[i] = currArray[i];
}
@ -248,12 +248,12 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
// Clone size
BukkitQueue_1_13.fieldSize.set(paletteBlock, size);
// Clone palette
DataBits currentBits = (DataBits) BukkitQueue_1_13.fieldBits.get(current);
DataBits newBits = new DataBits(currentBits.c(), currentBits.b(), currentBits.a().clone());
final DataBits currentBits = (DataBits) BukkitQueue_1_13.fieldBits.get(current);
final DataBits newBits = new DataBits(currentBits.c(), currentBits.b(), currentBits.a().clone());
BukkitQueue_1_13.fieldBits.set(paletteBlock, newBits);
// TODO copy only if different
Object defaultBlock = BukkitQueue_1_13.fieldDefaultBlock.get(current);
final Object defaultBlock = BukkitQueue_1_13.fieldDefaultBlock.get(current);
if (defaultBlock != AIR) {
ReflectionUtils.setFailsafeFieldValue(BukkitQueue_1_13.fieldDefaultBlock, paletteBlock, BukkitQueue_1_13.fieldDefaultBlock.get(current));
}
@ -262,8 +262,8 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
@Override
public IntFaweChunk<Chunk, BukkitQueue_1_13> copy(boolean shallow) {
BukkitChunk_1_13 copy;
public IntFaweChunk<Chunk, BukkitQueue_1_13> copy(final boolean shallow) {
final BukkitChunk_1_13 copy;
if (shallow) {
copy = new BukkitChunk_1_13(getParent(), getX(), getZ(), setBlocks, count, air);
copy.biomes = biomes;
@ -277,13 +277,13 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
copy.sectionPalettes = new ChunkSection[16];
try {
for (int i = 0; i < sectionPalettes.length; i++) {
ChunkSection current = sectionPalettes[i];
final ChunkSection current = sectionPalettes[i];
if (current == null) {
continue;
}
copy.sectionPalettes[i] = copy(current);
}
} catch (Throwable e) {
} catch (final Throwable e) {
MainUtil.handleError(e);
}
}
@ -303,13 +303,13 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
if (sectionPalettes != null) {
return;
}
int[][] arrays = getCombinedIdArrays();
final int[][] arrays = getCombinedIdArrays();
for (int layer = 0; layer < 16; layer++) {
if (getCount(layer) > 0) {
if (sectionPalettes == null) {
sectionPalettes = new ChunkSection[16];
}
int[] array = arrays[layer];
final int[] array = arrays[layer];
sectionPalettes[layer] = BukkitQueue_1_13.newChunkSection(layer, getParent().hasSky(), array);
}
}
@ -320,7 +320,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
getChunk().load(true);
}
private void removeEntity(Entity entity) {
private void removeEntity(final Entity entity) {
entity.b(false);
entity.die();
entity.valid = false;
@ -328,32 +328,32 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
@Override
public FaweChunk call() {
Spigot_v1_13_R2 adapter = (Spigot_v1_13_R2) BukkitQueue_0.getAdapter();
final Spigot_v1_13_R2 adapter = (Spigot_v1_13_R2) BukkitQueue_0.getAdapter();
try {
BukkitChunk_1_13 copy = getParent().getChangeTask() != null ? new BukkitChunk_1_13(getParent(), getX(), getZ()) : null;
final BukkitChunk_1_13 copy = getParent().getChangeTask() != null ? new BukkitChunk_1_13(getParent(), getX(), getZ()) : null;
final Chunk chunk = this.getChunk();
final World world = chunk.getWorld();
Settings settings = getParent().getSettings();
int bx = this.getX() << 4;
int bz = this.getZ() << 4;
final Settings settings = getParent().getSettings();
final int bx = this.getX() << 4;
final int bz = this.getZ() << 4;
final boolean flag = world.getEnvironment() == World.Environment.NORMAL;
net.minecraft.server.v1_13_R2.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
final net.minecraft.server.v1_13_R2.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
nmsChunk.f(true); // Set Modified
nmsChunk.mustSave = true;
nmsChunk.markDirty();
net.minecraft.server.v1_13_R2.World nmsWorld = nmsChunk.world;
ChunkSection[] sections = nmsChunk.getSections();
List<Entity>[] entities = nmsChunk.getEntitySlices();
Map<BlockPosition, TileEntity> tiles = nmsChunk.getTileEntities();
final net.minecraft.server.v1_13_R2.World nmsWorld = nmsChunk.world;
final ChunkSection[] sections = nmsChunk.getSections();
final List<Entity>[] entities = nmsChunk.getEntitySlices();
final Map<BlockPosition, TileEntity> tiles = nmsChunk.getTileEntities();
// Remove entities
HashSet<UUID> entsToRemove = this.getEntityRemoves();
final HashSet<UUID> entsToRemove = this.getEntityRemoves();
if (!entsToRemove.isEmpty()) {
for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = entities[i];
final Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
Iterator<Entity> iter = ents.iterator();
final Iterator<Entity> iter = ents.iterator();
while (iter.hasNext()) {
Entity entity = iter.next();
final Entity entity = iter.next();
if (entsToRemove.contains(entity.getUniqueID())) {
if (copy != null) {
copy.storeEntity(entity);
@ -368,16 +368,16 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
}
for (int i = 0; i < entities.length; i++) {
int count = this.getCount(i);
final int count = this.getCount(i);
if (count == 0 || settings.EXPERIMENTAL.KEEP_ENTITIES_IN_BLOCKS) {
continue;
} else if (count >= 4096) {
Collection<Entity> ents = entities[i];
final Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
synchronized (BukkitQueue_0.class) {
Iterator<Entity> iter = ents.iterator();
final Iterator<Entity> iter = ents.iterator();
while (iter.hasNext()) {
Entity entity = iter.next();
final Entity entity = iter.next();
if (entity instanceof EntityPlayer) {
continue;
}
@ -390,24 +390,24 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
}
} else {
Collection<Entity> ents = entities[i];
final Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
int layerYStart = i << 4;
int layerYEnd = layerYStart + 15;
int[] array = this.getIdArray(i);
final int layerYStart = i << 4;
final int layerYEnd = layerYStart + 15;
final int[] array = this.getIdArray(i);
if (array == null) continue;
Iterator<Entity> iter = ents.iterator();
final Iterator<Entity> iter = ents.iterator();
while (iter.hasNext()) {
Entity entity = iter.next();
final Entity entity = iter.next();
if (entity instanceof EntityPlayer) {
continue;
}
int y = MathMan.roundInt(entity.locY);
final int y = MathMan.roundInt(entity.locY);
if (y > layerYEnd || y < layerYStart) continue;
int x = (MathMan.roundInt(entity.locX) & 15);
int z = (MathMan.roundInt(entity.locZ) & 15);
final int x = (MathMan.roundInt(entity.locX) & 15);
final int z = (MathMan.roundInt(entity.locZ) & 15);
int index = (((y & 0xF) << 8) | (z << 4) | x);
final int index = (((y & 0xF) << 8) | (z << 4) | x);
if (array[index] != 0) {
if (copy != null) {
copy.storeEntity(entity);
@ -422,32 +422,32 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
}
// Set entities
Set<CompoundTag> entitiesToSpawn = this.getEntities();
final Set<CompoundTag> entitiesToSpawn = this.getEntities();
if (!entitiesToSpawn.isEmpty()) {
synchronized (BukkitQueue_0.class) {
for (CompoundTag nativeTag : entitiesToSpawn) {
Map<String, Tag> entityTagMap = ReflectionUtils.getMap(nativeTag.getValue());
StringTag idTag = (StringTag) entityTagMap.get("Id");
ListTag posTag = (ListTag) entityTagMap.get("Pos");
ListTag rotTag = (ListTag) entityTagMap.get("Rotation");
for (final CompoundTag nativeTag : entitiesToSpawn) {
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;
}
double x = posTag.getDouble(0);
double y = posTag.getDouble(1);
double z = posTag.getDouble(2);
float yaw = rotTag.getFloat(0);
float pitch = rotTag.getFloat(1);
String id = idTag.getValue();
Entity entity = EntityTypes.a(nmsWorld, new MinecraftKey(id));
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) {
UUID uuid = entity.getUniqueID();
final UUID uuid = entity.getUniqueID();
entityTagMap.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
entityTagMap.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
if (nativeTag != null) {
NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_13.fromNative(nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
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);
@ -462,11 +462,11 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
// Set blocks
for (int j = 0; j < sections.length; j++) {
int count = this.getCount(j);
final int count = this.getCount(j);
if (count == 0) {
continue;
}
int countAir = this.getAir(j);
final int countAir = this.getAir(j);
final int[] array = this.getIdArray(j);
if (array == null) {
continue;
@ -501,15 +501,15 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
continue;
}
}
int by = j << 4;
DataPaletteBlock<IBlockData> nibble = section.getBlocks();
final int by = j << 4;
final DataPaletteBlock<IBlockData> nibble = section.getBlocks();
int nonEmptyBlockCount = 0;
IBlockData existing;
for (int y = 0, i = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x= 0; x < 16; x++, i++) {
int combinedId = array[i];
final int combinedId = array[i];
switch (combinedId) {
case 0:
continue;
@ -534,8 +534,8 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
} else {
nonEmptyBlockCount++;
}
BlockState state = BlockState.getFromInternalId(combinedId);
IBlockData ibd = ((BlockMaterial_1_13) state.getMaterial()).getState();
final BlockState state = BlockState.getFromInternalId(combinedId);
final IBlockData ibd = ((BlockMaterial_1_13) state.getMaterial()).getState();
nibble.setBlock(x, y, z, ibd);
}
}
@ -547,19 +547,19 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
// Trim tiles
HashMap<BlockPosition, TileEntity> toRemove = null;
if (!tiles.isEmpty()) {
Iterator<Map.Entry<BlockPosition, TileEntity>> iterator = tiles.entrySet().iterator();
final Iterator<Map.Entry<BlockPosition, TileEntity>> iterator = tiles.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<BlockPosition, TileEntity> tile = iterator.next();
BlockPosition pos = tile.getKey();
int lx = pos.getX() & 15;
int ly = pos.getY();
int lz = pos.getZ() & 15;
int layer = ly >> 4;
int[] array = this.getIdArray(layer);
final Map.Entry<BlockPosition, TileEntity> tile = iterator.next();
final BlockPosition pos = tile.getKey();
final int lx = pos.getX() & 15;
final int ly = pos.getY();
final int lz = pos.getZ() & 15;
final int layer = ly >> 4;
final int[] array = this.getIdArray(layer);
if (array == null) {
continue;
}
int index = (((ly & 0xF) << 8) | (lz << 4) | lx);
final int index = (((ly & 0xF) << 8) | (lz << 4) | lx);
if (array[index] != 0) {
if (toRemove == null) {
toRemove = new HashMap<>();
@ -572,9 +572,9 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
}
if (toRemove != null) {
synchronized (BukkitQueue_0.class) {
for (Map.Entry<BlockPosition, TileEntity> entry : toRemove.entrySet()) {
BlockPosition bp = entry.getKey();
TileEntity tile = entry.getValue();
for (final Map.Entry<BlockPosition, TileEntity> entry : toRemove.entrySet()) {
final BlockPosition bp = entry.getKey();
final TileEntity tile = entry.getValue();
nmsWorld.n(bp);
tiles.remove(bp);
tile.z();
@ -586,32 +586,32 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
// Set biomes
if (this.biomes != null) {
BiomeBase[] currentBiomes = nmsChunk.getBiomeIndex();
final BiomeBase[] currentBiomes = nmsChunk.getBiomeIndex();
if (copy != null) {
copy.storeBiomes(currentBiomes);
}
for (int i = 0 ; i < this.biomes.length; i++) {
BiomeType biome = this.biomes[i];
final BiomeType biome = this.biomes[i];
if (biome != null) {
Biome craftBiome = adapter.adapt(biome);
final Biome craftBiome = adapter.adapt(biome);
currentBiomes[i] = CraftBlock.biomeToBiomeBase(craftBiome);
}
}
}
// Set tiles
Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
final Map<Short, CompoundTag> tilesToSpawn = this.getTiles();
if (!tilesToSpawn.isEmpty()) {
for (Map.Entry<Short, CompoundTag> entry : tilesToSpawn.entrySet()) {
CompoundTag nativeTag = entry.getValue();
short blockHash = entry.getKey();
int x = (blockHash >> 12 & 0xF) + bx;
int y = (blockHash & 0xFF);
int z = (blockHash >> 8 & 0xF) + bz;
BlockPosition pos = new BlockPosition(x, y, z); // Set pos
for (final Map.Entry<Short, CompoundTag> entry : tilesToSpawn.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); // Set pos
synchronized (BukkitQueue_0.class) {
TileEntity tileEntity = nmsWorld.getTileEntity(pos);
final TileEntity tileEntity = nmsWorld.getTileEntity(pos);
if (tileEntity != null) {
NBTTagCompound tag = (NBTTagCompound) BukkitQueue_1_13.fromNative(nativeTag);
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));
@ -624,7 +624,7 @@ public class BukkitChunk_1_13 extends IntFaweChunk<Chunk, BukkitQueue_1_13> {
if (copy != null) {
getParent().getChangeTask().run(copy, this);
}
} catch (Throwable e) {
} catch (final Throwable e) {
MainUtil.handleError(e);
}
return this;

Datei anzeigen

@ -195,7 +195,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
Fawe.debug("Using adapter: " + getAdapter());
Fawe.debug("=========================================");
} catch (Throwable e) {
} catch (final Throwable e) {
throw new RuntimeException(e);
}
}
@ -210,20 +210,20 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
getImpWorld();
}
private boolean save(net.minecraft.server.v1_13_R2.Chunk chunk, ChunkProviderServer cps) {
private boolean save(final net.minecraft.server.v1_13_R2.Chunk chunk, final ChunkProviderServer cps) {
cps.saveChunk(chunk, false);
chunk.a(false);
return true;
}
@Override
public ChunkSection[] getSections(net.minecraft.server.v1_13_R2.Chunk chunk) {
public ChunkSection[] getSections(final net.minecraft.server.v1_13_R2.Chunk chunk) {
return chunk.getSections();
}
@Override
public net.minecraft.server.v1_13_R2.Chunk loadChunk(World world, int x, int z, boolean generate) {
ChunkProviderServer provider = ((CraftWorld) world).getHandle().getChunkProvider();
public net.minecraft.server.v1_13_R2.Chunk loadChunk(final World world, final int x, final int z, final boolean generate) {
final ChunkProviderServer provider = ((CraftWorld) world).getHandle().getChunkProvider();
if (generate) {
return provider.getChunkAt(x, z, true, true);
} else {
@ -232,8 +232,8 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
}
@Override
public ChunkSection[] getCachedSections(World world, int cx, int cz) {
net.minecraft.server.v1_13_R2.Chunk chunk = ((CraftWorld) world).getHandle().getChunkProvider().getChunkAt(cx, cz, false, false);
public ChunkSection[] getCachedSections(final World world, final int cx, final int cz) {
final net.minecraft.server.v1_13_R2.Chunk chunk = ((CraftWorld) world).getHandle().getChunkProvider().getChunkAt(cx, cz, false, false);
if (chunk != null) {
return chunk.getSections();
}
@ -241,23 +241,23 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
}
@Override
public net.minecraft.server.v1_13_R2.Chunk getCachedChunk(World world, int cx, int cz) {
public net.minecraft.server.v1_13_R2.Chunk getCachedChunk(final World world, final int cx, final int cz) {
return ((CraftWorld) world).getHandle().getChunkProvider().getChunkAt(cx, cz, false, false);
}
@Override
public ChunkSection getCachedSection(ChunkSection[] chunkSections, int cy) {
public ChunkSection getCachedSection(final ChunkSection[] chunkSections, final int cy) {
return chunkSections[cy];
}
@Override
public void saveChunk(net.minecraft.server.v1_13_R2.Chunk chunk) {
public void saveChunk(final net.minecraft.server.v1_13_R2.Chunk chunk) {
chunk.f(true); // Set Modified
chunk.mustSave = true;
}
@Override
public boolean regenerateChunk(World world, int x, int z, BiomeType biome, Long seed) {
public boolean regenerateChunk(final World world, final int x, final int z, final BiomeType biome, final Long seed) {
// if (biome != null) {
// try {
// if (seed == null) {
@ -424,17 +424,17 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
}
@Override
public boolean next(int amount, long time) {
public boolean next(final int amount, final long time) {
return super.next(amount, time);
}
@Override
public void setSkyLight(ChunkSection section, int x, int y, int z, int value) {
public void setSkyLight(final ChunkSection section, final int x, final int y, final int z, final int value) {
section.getSkyLightArray().a(x & 15, y & 15, z & 15, value);
}
@Override
public void setBlockLight(ChunkSection section, int x, int y, int z, int value) {
public void setBlockLight(final ChunkSection section, final int x, final int y, final int z, final int value) {
section.getEmittedLightArray().a(x & 15, y & 15, z & 15, value);
}
@ -522,54 +522,54 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
// }
@Override
public int getCombinedId4Data(ChunkSection lastSection, int x, int y, int z) {
DataPaletteBlock<IBlockData> dataPalette = lastSection.getBlocks();
IBlockData ibd = dataPalette.a(x & 15, y & 15, z & 15);
int ordinal = ((Spigot_v1_13_R2) getAdapter()).adaptToInt(ibd);
public int getCombinedId4Data(final ChunkSection lastSection, final int x, final int y, final int z) {
final DataPaletteBlock<IBlockData> dataPalette = lastSection.getBlocks();
final IBlockData ibd = dataPalette.a(x & 15, y & 15, z & 15);
final int ordinal = ((Spigot_v1_13_R2) getAdapter()).adaptToInt(ibd);
return BlockTypes.states[ordinal].getInternalId();
}
@Override
public BiomeType getBiome(net.minecraft.server.v1_13_R2.Chunk chunk, int x, int z) {
BiomeBase base = chunk.getBiomeIndex()[((z & 15) << 4) + (x & 15)];
public BiomeType getBiome(final net.minecraft.server.v1_13_R2.Chunk chunk, final int x, final int z) {
final BiomeBase base = chunk.getBiomeIndex()[((z & 15) << 4) + (x & 15)];
return getAdapter().adapt(CraftBlock.biomeBaseToBiome(base));
}
@Override
public int getOpacity(ChunkSection section, int x, int y, int z) {
DataPaletteBlock<IBlockData> dataPalette = section.getBlocks();
IBlockData ibd = dataPalette.a(x & 15, y & 15, z & 15);
public int getOpacity(final ChunkSection section, final int x, final int y, final int z) {
final DataPaletteBlock<IBlockData> dataPalette = section.getBlocks();
final IBlockData ibd = dataPalette.a(x & 15, y & 15, z & 15);
pos.a(x, y, z);
return ibd.b(nmsWorld, pos);
}
@Override
public int getBrightness(ChunkSection section, int x, int y, int z) {
DataPaletteBlock<IBlockData> dataPalette = section.getBlocks();
IBlockData ibd = dataPalette.a(x & 15, y & 15, z & 15);
public int getBrightness(final ChunkSection section, final int x, final int y, final int z) {
final DataPaletteBlock<IBlockData> dataPalette = section.getBlocks();
final IBlockData ibd = dataPalette.a(x & 15, y & 15, z & 15);
return ibd.e();
}
@Override
public int getOpacityBrightnessPair(ChunkSection section, int x, int y, int z) {
DataPaletteBlock<IBlockData> dataPalette = section.getBlocks();
IBlockData ibd = dataPalette.a(x & 15, y & 15, z & 15);
public int getOpacityBrightnessPair(final ChunkSection section, final int x, final int y, final int z) {
final DataPaletteBlock<IBlockData> dataPalette = section.getBlocks();
final IBlockData ibd = dataPalette.a(x & 15, y & 15, z & 15);
pos.a(x, y, z);
int opacity = ibd.b(nmsWorld, pos);
int brightness = ibd.e();
final int opacity = ibd.b(nmsWorld, pos);
final int brightness = ibd.e();
return MathMan.pair16(brightness, opacity);
}
@Override
public void sendChunk(int x, int z, int bitMask) {
net.minecraft.server.v1_13_R2.Chunk chunk = getCachedChunk(getWorld(), x, z);
public void sendChunk(final int x, final int z, final int bitMask) {
final net.minecraft.server.v1_13_R2.Chunk chunk = getCachedChunk(getWorld(), x, z);
if (chunk != null) {
sendChunk(getPlayerChunk((WorldServer) chunk.getWorld(), chunk.locX, chunk.locZ), chunk, bitMask);
}
}
@Override
public void sendChunkUpdatePLIB(FaweChunk chunk, FawePlayer... players) {
public void sendChunkUpdatePLIB(final FaweChunk chunk, final FawePlayer... players) {
// PlayerChunkMap playerManager = ((CraftWorld) getWorld()).getHandle().getPlayerChunkMap();
// ProtocolManager manager = ProtocolLibrary.getProtocolManager();
// WirePacket packet = null;
@ -602,13 +602,13 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
}
@Override
public void sendBlockUpdate(FaweChunk chunk, FawePlayer... players) {
public void sendBlockUpdate(final FaweChunk chunk, final FawePlayer... players) {
try {
PlayerChunkMap playerManager = ((CraftWorld) getWorld()).getHandle().getPlayerChunkMap();
final PlayerChunkMap playerManager = ((CraftWorld) getWorld()).getHandle().getPlayerChunkMap();
boolean watching = false;
boolean[] watchingArr = new boolean[players.length];
final boolean[] watchingArr = new boolean[players.length];
for (int i = 0; i < players.length; i++) {
EntityPlayer player = ((CraftPlayer) ((BukkitPlayer) players[i]).parent).getHandle();
final EntityPlayer player = ((CraftPlayer) ((BukkitPlayer) players[i]).parent).getHandle();
if (playerManager.a(player, chunk.getX(), chunk.getZ())) {
watchingArr[i] = true;
watching = true;
@ -623,22 +623,22 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
} else {
chunk.forEachQueuedBlock(new FaweChunkVisitor() {
@Override
public void run(int localX, int y, int localZ, int combined) {
public void run(final int localX, final int y, final int localZ, final int combined) {
size.add(1);
}
});
}
if (size.intValue() == 0) return;
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer();
final PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
final ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer();
final PacketDataSerializer buffer = new PacketDataSerializer(byteBuf);
buffer.writeInt(chunk.getX());
buffer.writeInt(chunk.getZ());
buffer.d(size.intValue());
chunk.forEachQueuedBlock(new FaweChunkVisitor() {
@Override
public void run(int localX, int y, int localZ, int combined) {
short index = (short) (localX << 12 | localZ << 8 | y);
public void run(final int localX, final int y, final int localZ, int combined) {
final short index = (short) (localX << 12 | localZ << 8 | y);
if (combined < 16) combined = 0;
buffer.writeShort(index);
buffer.d(combined);
@ -648,28 +648,28 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
for (int i = 0; i < players.length; i++) {
if (watchingArr[i]) ((CraftPlayer) ((BukkitPlayer) players[i]).parent).getHandle().playerConnection.sendPacket(packet);
}
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
}
}
@Override
public void refreshChunk(FaweChunk fc) {
public void refreshChunk(final FaweChunk fc) {
sendChunk(fc.getX(), fc.getZ(), fc.getBitMask());
}
public void sendPacket(int cx, int cz, Packet packet) {
PlayerChunk chunk = getPlayerChunk(nmsWorld, cx, cz);
public void sendPacket(final int cx, final int cz, final Packet packet) {
final PlayerChunk chunk = getPlayerChunk(nmsWorld, cx, cz);
if (chunk != null) {
for (EntityPlayer player : chunk.players) {
for (final EntityPlayer player : chunk.players) {
player.playerConnection.sendPacket(packet);
}
}
}
private PlayerChunk getPlayerChunk(WorldServer w, int cx, int cz) {
PlayerChunkMap chunkMap = w.getPlayerChunkMap();
PlayerChunk playerChunk = chunkMap.getChunk(cx, cz);
private PlayerChunk getPlayerChunk(final WorldServer w, final int cx, final int cz) {
final PlayerChunkMap chunkMap = w.getPlayerChunkMap();
final PlayerChunk playerChunk = chunkMap.getChunk(cx, cz);
if (playerChunk == null) {
return null;
}
@ -679,12 +679,12 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
return playerChunk;
}
public boolean sendChunk(PlayerChunk playerChunk, net.minecraft.server.v1_13_R2.Chunk nmsChunk, int mask) {
public boolean sendChunk(final PlayerChunk playerChunk, final net.minecraft.server.v1_13_R2.Chunk nmsChunk, final int mask) {
if (playerChunk == null) {
return false;
}
if (playerChunk.e()) {
ChunkSection[] sections = nmsChunk.getSections();
final ChunkSection[] sections = nmsChunk.getSections();
for (int layer = 0; layer < 16; layer++) {
if (sections[layer] == null && (mask & (1 << layer)) != 0) {
sections[layer] = new ChunkSection(layer << 4, nmsWorld.worldProvider.g());
@ -706,7 +706,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
fieldDirtyBits.set(playerChunk, dirtyBits);
fieldDirtyCount.set(playerChunk, 64);
} catch (IllegalAccessException e) {
} catch (final IllegalAccessException e) {
e.printStackTrace();
}
return null;
@ -750,25 +750,25 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
return true;
}
public boolean hasEntities(net.minecraft.server.v1_13_R2.Chunk nmsChunk) {
public boolean hasEntities(final net.minecraft.server.v1_13_R2.Chunk nmsChunk) {
try {
final Collection<Entity>[] entities = nmsChunk.entitySlices;
for (int i = 0; i < entities.length; i++) {
Collection<Entity> slice = entities[i];
final Collection<Entity> slice = entities[i];
if (slice != null && !slice.isEmpty()) {
return true;
}
}
} catch (Throwable ignore) {}
} catch (final Throwable ignore) {}
return false;
}
@Override
public boolean removeSectionLighting(ChunkSection section, int layer, boolean sky) {
public boolean removeSectionLighting(final ChunkSection section, final int layer, final boolean sky) {
if (section != null) {
Arrays.fill(section.getEmittedLightArray().asBytes(), (byte) 0);
if (sky) {
byte[] light = section.getSkyLightArray().asBytes();
final byte[] light = section.getSkyLightArray().asBytes();
if (light != null) {
Arrays.fill(light, (byte) 0);
}
@ -779,40 +779,40 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
}
@Override
public void setFullbright(ChunkSection[] sections) {
public void setFullbright(final ChunkSection[] sections) {
for (int i = 0; i < sections.length; i++) {
ChunkSection section = sections[i];
final ChunkSection section = sections[i];
if (section != null) {
byte[] bytes = section.getSkyLightArray().asBytes();
final byte[] bytes = section.getSkyLightArray().asBytes();
Arrays.fill(bytes, (byte) 255);
}
}
}
@Override
public int getSkyLight(ChunkSection section, int x, int y, int z) {
public int getSkyLight(final ChunkSection section, final int x, final int y, final int z) {
return section.c(x & 15, y & 15, z & 15);
}
@Override
public int getEmmittedLight(ChunkSection section, int x, int y, int z) {
public int getEmmittedLight(final ChunkSection section, final int x, final int y, final int z) {
return section.d(x & 15, y & 15, z & 15);
}
@Override
public void relightBlock(int x, int y, int z) {
public void relightBlock(final int x, final int y, final int z) {
pos.c(x, y, z);
nmsWorld.c(EnumSkyBlock.BLOCK, pos);
}
@Override
public void relightSky(int x, int y, int z) {
public void relightSky(final int x, final int y, final int z) {
pos.c(x, y, z);
nmsWorld.c(EnumSkyBlock.SKY, pos);
}
@Override
public void relight(int x, int y, int z) {
public void relight(final int x, final int y, final int z) {
pos.c(x, y, z);
nmsWorld.r(pos);
}
@ -821,7 +821,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
@Override
public World getImpWorld() {
World world = super.getImpWorld();
final World world = super.getImpWorld();
if (world != null) {
this.nmsWorld = ((CraftWorld) world).getHandle();
return super.getImpWorld();
@ -830,30 +830,30 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
}
}
public static void setCount(int tickingBlockCount, int nonEmptyBlockCount, ChunkSection section) throws NoSuchFieldException, IllegalAccessException {
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);
}
public int getNonEmptyBlockCount(ChunkSection section) throws IllegalAccessException {
public int getNonEmptyBlockCount(final ChunkSection section) throws IllegalAccessException {
return (int) fieldNonEmptyBlockCount.get(section);
}
public void setPalette(ChunkSection section, DataPaletteBlock palette) throws NoSuchFieldException, IllegalAccessException {
public void setPalette(final ChunkSection section, final DataPaletteBlock palette) throws NoSuchFieldException, IllegalAccessException {
fieldSection.set(section, palette);
Arrays.fill(section.getEmittedLightArray().asBytes(), (byte) 0);
}
public static ChunkSection newChunkSection(int y2, boolean flag, int[] blocks) {
public static ChunkSection newChunkSection(final int y2, final boolean flag, final int[] blocks) {
if (blocks == null) {
return new ChunkSection(y2 << 4, flag);
} else {
ChunkSection section = new ChunkSection(y2 << 4, flag);
int[] blockToPalette = FaweCache.BLOCK_TO_PALETTE.get();
int[] paletteToBlock = FaweCache.PALETTE_TO_BLOCK.get();
long[] blockstates = FaweCache.BLOCK_STATES.get();
int[] blocksCopy = FaweCache.SECTION_BLOCKS.get();
final ChunkSection section = new ChunkSection(y2 << 4, flag);
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;
@ -867,7 +867,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
stateId = BlockID.AIR;
air++;
}
int ordinal = BlockState.getFromInternalId(stateId).getOrdinal(); // TODO fixme Remove all use of BlockTypes.BIT_OFFSET so that this conversion isn't necessary
final int ordinal = BlockState.getFromInternalId(stateId).getOrdinal(); // TODO fixme Remove all use of BlockTypes.BIT_OFFSET so that this conversion isn't necessary
int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) {
blockToPalette[ordinal] = palette = num_palette;
@ -885,30 +885,30 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
bitsPerEntry = Math.max(bitsPerEntry, 1); // For some reason minecraft needs 4096 bits to store 0 entries
}
int blockBitArrayEnd = (bitsPerEntry * 4096) >> 6;
final int blockBitArrayEnd = (bitsPerEntry * 4096) >> 6;
if (num_palette == 1) {
for (int i = 0; i < blockBitArrayEnd; i++) blockstates[i] = 0;
} else {
BitArray4096 bitArray = new BitArray4096(blockstates, bitsPerEntry);
final BitArray4096 bitArray = new BitArray4096(blockstates, bitsPerEntry);
bitArray.fromRaw(blocksCopy);
}
// set palette & data bits
DataPaletteBlock<IBlockData> dataPaletteBlocks = section.getBlocks();
final DataPaletteBlock<IBlockData> dataPaletteBlocks = section.getBlocks();
// private DataPalette<T> h;
// protected DataBits a;
long[] bits = Arrays.copyOfRange(blockstates, 0, blockBitArrayEnd);
DataBits nmsBits = new DataBits(bitsPerEntry, 4096, bits);
DataPalette<IBlockData> palette;
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++) {
int ordinal = paletteToBlock[i];
final int ordinal = paletteToBlock[i];
blockToPalette[ordinal] = Integer.MAX_VALUE;
BlockState state = BlockTypes.states[ordinal];
IBlockData ibd = ((BlockMaterial_1_13) state.getMaterial()).getState();
final BlockState state = BlockTypes.states[ordinal];
final IBlockData ibd = ((BlockMaterial_1_13) state.getMaterial()).getState();
palette.a(ibd);
}
try {
@ -916,12 +916,12 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
fieldPalette.set(dataPaletteBlocks, palette);
fieldSize.set(dataPaletteBlocks, bitsPerEntry);
setCount(0, 4096 - air, section);
} catch (IllegalAccessException | NoSuchFieldException e) {
} catch (final IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
return section;
} catch (Throwable e){
} catch (final Throwable e){
Arrays.fill(blockToPalette, Integer.MAX_VALUE);
throw e;
}
@ -931,19 +931,19 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
protected BlockPosition.MutableBlockPosition pos = new BlockPosition.MutableBlockPosition(0, 0, 0);
@Override
public CompoundTag getTileEntity(net.minecraft.server.v1_13_R2.Chunk chunk, int x, int y, int z) {
Map<BlockPosition, TileEntity> tiles = chunk.getTileEntities();
public CompoundTag getTileEntity(final net.minecraft.server.v1_13_R2.Chunk chunk, final int x, final int y, final int z) {
final Map<BlockPosition, TileEntity> tiles = chunk.getTileEntities();
pos.c(x, y, z);
TileEntity tile = tiles.get(pos);
final TileEntity tile = tiles.get(pos);
return tile != null ? getTag(tile) : null;
}
public CompoundTag getTag(TileEntity tile) {
public CompoundTag getTag(final TileEntity tile) {
try {
NBTTagCompound tag = new NBTTagCompound();
final NBTTagCompound tag = new NBTTagCompound();
tile.save(tag); // readTagIntoEntity
return (CompoundTag) toNative(tag);
} catch (Exception e) {
} catch (final Exception e) {
MainUtil.handleError(e);
return null;
}
@ -951,7 +951,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
@Deprecated
public boolean unloadChunk(final String world, final Chunk chunk) {
net.minecraft.server.v1_13_R2.Chunk c = ((CraftChunk) chunk).getHandle();
final net.minecraft.server.v1_13_R2.Chunk c = ((CraftChunk) chunk).getHandle();
c.mustSave = false;
if (chunk.isLoaded()) {
chunk.unload(false, false);
@ -960,7 +960,7 @@ public class BukkitQueue_1_13 extends BukkitQueue_0<net.minecraft.server.v1_13_R
}
@Override
public BukkitChunk_1_13 getFaweChunk(int x, int z) {
public BukkitChunk_1_13 getFaweChunk(final int x, final int z) {
return new BukkitChunk_1_13(this, x, z);
}
}

Datei anzeigen

@ -1,42 +0,0 @@
package com.boydti.fawe.bukkit.v1_13;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
import com.boydti.fawe.bukkit.v1_13.beta.holder.ChunkHolder;
import com.boydti.fawe.bukkit.v1_13.beta.holder.IDelegateChunk;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
public interface IQueueExtent {
void init(World world);
IChunk getCachedChunk(int X, int Z);
default boolean setBlock(int x, int y, int z, BlockStateHolder state) {
IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.setBlock(x & 15, y, z & 15, state);
}
default boolean setBiome(int x, int y, int z, BiomeType biome) {
IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.setBiome(x & 15, y, z & 15, biome);
}
default BlockState getBlock(int x, int y, int z) {
IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBlock(x & 15, y, z & 15);
}
default BiomeType getBiome(int x, int z) {
IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBiome(x & 15, z & 15);
}
// Return ChunkHolder
ChunkHolder create(boolean full);
// Region restrictions
IDelegateChunk wrap(IChunk root);
}

Datei anzeigen

@ -1,5 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta;
public class CharBlocks implements IBlocks {
protected char[][] blocks;
}

Datei anzeigen

@ -1,7 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import com.boydti.fawe.bukkit.v1_13.IQueueExtent;
public interface IDelegateQueueExtent {
IQueueExtent getParent();
}

Datei anzeigen

@ -1,5 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta;
public interface IBlocks {
}

Datei anzeigen

@ -1,83 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.Region;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
public class QueueHandler {
private SingleThreadQueueExtent mainExtent;
private SingleThreadQueueExtent[] pool;
public static void apply(Region region, Filter filter) { // TODO not MCAFilter, but another similar class
// The chunks positions to iterate over
Set<BlockVector2> chunks = region.getChunks();
Iterator<BlockVector2> chunksIter = chunks.iterator();
// Get a pool, to operate on the chunks in parallel
ForkJoinPool pool = TaskManager.IMP.getPublicForkJoinPool();
int size = Math.min(chunks.size(), Settings.IMP.QUEUE.PARALLEL_THREADS);
ForkJoinTask[] tasks = new ForkJoinTask[size];
for (int i = 0; i < size; i++) {
tasks[i] = pool.submit(new Runnable() {
@Override
public void run() {
// Create a chunk that we will reuse/reset for each operation
IChunk chunk = create(true);
while (true) {
// Get the next chunk pos
BlockVector2 pos;
synchronized (chunksIter) {
if (!chunksIter.hasNext()) return;
pos = chunksIter.next();
}
int X = pos.getX();
int Z = pos.getZ();
long pair = MathMan.pairInt(X, Z);
// Initialize
chunk.init(SingleThreadQueueExtent.this, X, Z);
{ // Start set
lastPair = pair;
lastChunk = chunk;
}
try {
if (!filter.appliesChunk(X, Z)) {
continue;
}
chunk = filter.applyChunk(chunk);
if (chunk == null) continue;
chunk.filter(filter);
filter.finishChunk(chunk);
chunk.apply();
} finally
{ // End set
lastPair = Long.MAX_VALUE;
lastChunk = null;
}
}
}
});
}
// Join the tasks
for (ForkJoinTask task : tasks) {
task.join();
}
}
}

Datei anzeigen

@ -1,104 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta;
import com.boydti.fawe.bukkit.v1_13.IQueueExtent;
import com.boydti.fawe.bukkit.v1_13.beta.holder.ChunkHolder;
import com.boydti.fawe.bukkit.v1_13.beta.holder.IDelegateChunk;
import com.boydti.fawe.bukkit.v1_13.beta.holder.ReferenceChunk;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.wrappers.WorldWrapper;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.World;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class SingleThreadQueueExtent implements IQueueExtent {
private WorldWrapper wrapped;
private World world;
public World getWorld() {
return world;
}
public WorldWrapper getWrappedWorld() {
return wrapped;
}
private void reset() {
wrapped = null;
world = null;
chunks.clear();
lastChunk = null;
lastPair = Long.MAX_VALUE;
}
public synchronized void init(World world) {
if (world != null) {
reset();
}
checkNotNull(world);
if (world instanceof EditSession) {
world = ((EditSession) world).getWorld();
}
checkNotNull(world);
if (world instanceof WorldWrapper) {
this.wrapped = (WorldWrapper) world;
world = WorldWrapper.unwrap(world);
} else {
this.wrapped = WorldWrapper.wrap(world);
}
this.world = world;
}
private IChunk lastChunk;
private long lastPair = Long.MAX_VALUE;
private final Long2ObjectLinkedOpenHashMap<IDelegateChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();
private final IDelegateChunk getCachedChunk2(long pair) {
IDelegateChunk chunk = chunks.get(pair);
if (chunk instanceof ReferenceChunk) {
chunk = (ReferenceChunk) (chunk).getParent();
}
if (chunk != null) {
lastPair = pair;
lastChunk = chunk;
}
return chunk;
}
public final IChunk getCachedChunk(int X, int Z) {
long pair = MathMan.pairInt(X, Z);
if (pair == lastPair) {
return lastChunk;
}
IDelegateChunk chunk = getCachedChunk2(pair);
if (chunk != null) return chunk;
chunk = getCachedChunk2(pair);
if (chunk != null) return chunk;
int size = chunks.size();
if (size > Settings.IMP.QUEUE.TARGET_SIZE || MemUtil.isMemoryLimited()) {
if (size > Settings.IMP.QUEUE.PARALLEL_THREADS * 2 + 16) {
chunk = chunks.removeFirst();
chunk.apply();
chunk = (IDelegateChunk) chunk.findParent(ChunkHolder.class);
chunk.init(this, X, Z);
} else {
chunk = create(false);
}
} else {
chunk = create(false);
}
chunk = wrap(chunk);
chunks.put(pair, chunk);
lastPair = pair;
lastChunk = chunk;
return chunk;
}
}

Datei anzeigen

@ -1,30 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.bukkit;
import com.boydti.fawe.bukkit.v1_13.beta.SingleThreadQueueExtent;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.world.World;
import net.minecraft.server.v1_13_R2.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import static com.google.common.base.Preconditions.checkNotNull;
public class BukkitReusableExtent extends SingleThreadQueueExtent {
private org.bukkit.World bukkitWorld;
private WorldServer nmsWorld;
public void init(World world) {
super.init(world);
world = 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();
}
}

Datei anzeigen

@ -1,21 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.CharGetBlocks;
import com.boydti.fawe.bukkit.v1_13.beta.CharSetBlocks;
import com.boydti.fawe.bukkit.v1_13.beta.IGetBlocks;
import com.boydti.fawe.bukkit.v1_13.beta.ISetBlocks;
public class ChunkHolder extends DelegateChunk<DelegateChunk> {
public ChunkHolder() {
super(new InitChunk(null));
getParent().setParent(this);
}
protected final IGetBlocks get() {
return new CharGetBlocks();
}
protected final ISetBlocks set() {
return new CharSetBlocks();
}
}

Datei anzeigen

@ -1,16 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
public class FinalizedChunk extends DelegateChunk {
public FinalizedChunk(IChunk parent) {
super(parent);
}
@Override
protected void finalize() throws Throwable {
apply();
setParent(null);
super.finalize();
}
}

Datei anzeigen

@ -1,44 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IGetBlocks;
import com.boydti.fawe.bukkit.v1_13.beta.ISetBlocks;
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;
public class FullChunk extends DelegateChunk<ChunkHolder> {
private final ISetBlocks set;
private final IGetBlocks get;
public FullChunk(ChunkHolder parent, IGetBlocks get, ISetBlocks set) {
super(parent);
this.set = set == null ? parent.set() : set;
this.get = get == null ? parent.get() : get;
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return get.getFullBlock(x, y, z);
}
@Override
public BiomeType getBiome(int x, int z) {
return get.getBiome(x, z);
}
@Override
public BlockState getBlock(int x, int y, int z) {
return get.getBlock(x, y, z);
}
@Override
public void setBiome(int x, int z, BiomeType biome) {
set.setBiome(x, z, biome);
}
@Override
public void setBlock(int x, int y, int z, BlockStateHolder holder) {
set.setBlock(x, y, z, holder);
}
}

Datei anzeigen

@ -1,34 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IGetBlocks;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
public class GetChunk extends InitChunk {
private final IGetBlocks get;
public GetChunk(ChunkHolder parent) {
super(parent);
this.get = parent.get();
}
protected void init() {
getParent().setParent(new FullChunk(getParent(), get, null));
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return get.getFullBlock(x, y, z);
}
@Override
public BiomeType getBiome(int x, int z) {
return get.getBiome(x, z);
}
@Override
public BlockState getBlock(int x, int y, int z) {
return get.getBlock(x, y, z);
}
}

Datei anzeigen

@ -1,47 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
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;
public class InitChunk extends DelegateChunk<ChunkHolder> {
public InitChunk(ChunkHolder parent) {
super(parent);
}
protected void init() {
getParent().setParent(new SetChunk(getParent()));
}
@Override
public void setBiome(int x, int z, BiomeType biome) {
init();
super.setBiome(x, z, biome);
}
@Override
public void setBlock(int x, int y, int z, BlockStateHolder holder) {
init();
super.setBlock(x, y, z, holder);
}
@Override
public BiomeType getBiome(int x, int z) {
init();
return super.getBiome(x, z);
}
@Override
public BlockState getBlock(int x, int y, int z) {
init();
return super.getBlock(x, y, z);
}
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
init();
return super.getFullBlock(x, y, z);
}
}

Datei anzeigen

@ -1,23 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
public abstract class ReferenceChunk implements IDelegateChunk {
private final Reference<FinalizedChunk> ref;
public ReferenceChunk(IChunk parent) {
this.ref = toRef(new FinalizedChunk(parent));
}
protected abstract Reference<FinalizedChunk> toRef(FinalizedChunk parent);
@Override
public IChunk getParent() {
FinalizedChunk finalized = ref.get();
return finalized != null ? finalized.getParent() : null;
}
}

Datei anzeigen

@ -1,30 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
import com.boydti.fawe.bukkit.v1_13.beta.ISetBlocks;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
public class SetChunk extends InitChunk {
private final ISetBlocks set;
public SetChunk(ChunkHolder parent) {
super(parent);
this.set = parent.set();
}
protected void init() {
getParent().setParent(new FullChunk(getParent(), null, set));
}
@Override
public void setBiome(int x, int z, BiomeType biome) {
set.setBiome(x, z, biome);
}
@Override
public void setBlock(int x, int y, int z, BlockStateHolder holder) {
set.setBlock(x, y, z, holder);
}
}

Datei anzeigen

@ -1,18 +0,0 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
public class SoftChunk extends ReferenceChunk {
public SoftChunk(IChunk parent) {
super(parent);
}
@Override
protected Reference<FinalizedChunk> toRef(FinalizedChunk parent) {
return new SoftReference<>(parent);
}
}

Datei anzeigen

@ -31,22 +31,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* [ WorldEdit action]
* |
* |
* \|/
* [ EditSession ] - The change is processed (area restrictions, change limit, block type)
* |
* |
* \|/
* [Block change] - A block change from some location
* |
* |
* \|/
* [ Set Queue ] - The SetQueue manages the implementation specific queue
* |
* |
* \|/
* [ Fawe Queue] - A queue of chunks - check if the queue has the chunk for a change
* |
* |
* \|/
* [ Fawe Chunk Implementation ] - Otherwise create a new FaweChunk object which is a wrapper around the Chunk object
* |
* |
* \|/
* [ Execution ] - When done, the queue then sets the blocks for the chunk, performs lighting updates and sends the chunk packet to the clients
* <p>

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe;
import com.boydti.fawe.beta.Trimable;
import com.boydti.fawe.jnbt.anvil.BitArray4096;
import com.boydti.fawe.object.collection.IterableThreadLocal;
import com.boydti.fawe.util.MathMan;
@ -11,29 +12,21 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import java.lang.reflect.Field;
import java.util.*;
public class FaweCache {
public static final IterableThreadLocal<char[]> BLOCK_TO_PALETTE_CHAR = new IterableThreadLocal<char[]>() {
@Override
public char[] init() {
char[] result = new char[BlockTypes.states.length];
Arrays.fill(result, Character.MAX_VALUE);
return result;
}
};
public class FaweCache implements Trimable {
public static final IterableThreadLocal<char[]> PALETTE_TO_BLOCK_CHAR = new IterableThreadLocal<char[]>() {
@Override
public char[] init() {
return new char[Character.MAX_VALUE];
}
};
/*
Palette buffers / cache
*/
public static final IterableThreadLocal<char[]> SECTION_BLOCKS_CHAR = new IterableThreadLocal<char[]>() {
@Override
public char[] init() {
return new char[4096];
}
};
@Override
public boolean trim(boolean aggressive) {
BLOCK_TO_PALETTE.clean();
PALETTE_TO_BLOCK.clean();
BLOCK_STATES.clean();
SECTION_BLOCKS.clean();
PALETTE_CACHE.clean();
return false;
}
public static final IterableThreadLocal<int[]> BLOCK_TO_PALETTE = new IterableThreadLocal<int[]>() {
@Override
@ -75,6 +68,121 @@ public class FaweCache {
return map;
}
private 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 layer
* @param blocks
* @return palette
*/
public static Palette toPalette(int layer, char[] blocks) {
return toPalette(layer, null, blocks);
}
/**
* Convert raw int array to palette
* @param layer
* @param blocks
* @return palette
*/
public static Palette toPalette(int layer, int[] blocks) {
return toPalette(layer, blocks, null);
}
private static Palette toPalette(int layer, 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 = layer << 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;
}
}
/*
Conversion methods between JNBT tags and raw values
*/
public static ShortTag asTag(short value) {
return new ShortTag(value);
}
@ -205,56 +313,4 @@ public class FaweCache {
if (clazz == null) clazz = EndTag.class;
return new ListTag(clazz, list);
}
private static final class Palette {
}
public void toPalette(int layer, char[] blocks) {
int[] blockToPalette = FaweCache.BLOCK_TO_PALETTE.get();
int[] paletteToBlock = FaweCache.PALETTE_TO_BLOCK.get();
long[] blockstates = FaweCache.BLOCK_STATES.get();
int[] blocksCopy = FaweCache.SECTION_BLOCKS.get();
int blockIndexStart = layer << 12;
int blockIndexEnd = blockIndexStart + 4096;
int num_palette = 0;
try {
for (int i = blockIndexStart, j = 0; i < blockIndexEnd; i++, j++) {
int ordinal = blocks[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;
}
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);
}
// num_palette
// paletteToBlock
// blockstates (range: blockBitArrayEnd)
} catch (Throwable e) {
Arrays.fill(blockToPalette, Integer.MAX_VALUE);
e.printStackTrace();
throw e;
}
}
}

Datei anzeigen

@ -1,8 +1,8 @@
package com.boydti.fawe.bukkit.v1_13.beta;
package com.boydti.fawe.beta;
import com.sk89q.worldedit.world.block.BaseBlock;
public class Filter {
public interface Filter {
/**
* Check whether a chunk should be read
*
@ -10,7 +10,7 @@ public class Filter {
* @param cz
* @return
*/
public boolean appliesChunk(int cx, int cz) {
default boolean appliesChunk(final int cx, final int cz) {
return true;
}
@ -22,7 +22,7 @@ public class Filter {
* @param chunk
* @return
*/
public IChunk applyChunk(IChunk chunk) {
default IChunk applyChunk(final IChunk chunk) {
return chunk;
}
@ -36,7 +36,7 @@ public class Filter {
* @param z
* @param block
*/
public void applyBlock(int x, int y, int z, BaseBlock block) {
default void applyBlock(final int x, final int y, final int z, final BaseBlock block) {
}
/**
@ -45,6 +45,6 @@ public class Filter {
* @param chunk
* @return
*/
public void finishChunk(IChunk chunk) {
default void finishChunk(final IChunk chunk) {
}
}

Datei anzeigen

@ -0,0 +1,5 @@
package com.boydti.fawe.beta;
public interface IBlocks {
}

Datei anzeigen

@ -1,15 +1,15 @@
package com.boydti.fawe.bukkit.v1_13.beta;
package com.boydti.fawe.beta;
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;
public interface IChunk {
public interface IChunk<T, V extends IQueueExtent> {
/* set */
boolean setBiome(int x, int y, int z, BiomeType biome);
boolean setBlock(int x, int y, int z, BlockStateHolder holder);
boolean setBlock(int x, int y, int z, BlockStateHolder block);
/* get */
BiomeType getBiome(int x, int z);
@ -18,14 +18,14 @@ public interface IChunk {
BaseBlock getFullBlock(int x, int y, int z);
void init(SingleThreadQueueExtent extent, int X, int Z);
void init(V extent, int X, int Z);
T apply();
int getX();
int getZ();
void apply();
default IChunk getRoot() {
return this;
}

Datei anzeigen

@ -1,14 +1,13 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
package com.boydti.fawe.beta;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
import com.boydti.fawe.bukkit.v1_13.beta.SingleThreadQueueExtent;
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
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;
public interface IDelegateChunk<T extends IChunk> extends IChunk {
T getParent();
public interface IDelegateChunk<T, V extends IQueueExtent, U extends IChunk<T, V>> extends IChunk<T, V> {
U getParent();
default IChunk getRoot() {
IChunk root = getParent();
@ -19,32 +18,32 @@ public interface IDelegateChunk<T extends IChunk> extends IChunk {
}
@Override
default void setBiome(int x, int z, BiomeType biome) {
getParent().setBiome(x, z, biome);
default boolean setBiome(final int x, final int y, final int z, final BiomeType biome) {
return getParent().setBiome(x, y, z, biome);
}
@Override
default void setBlock(int x, int y, int z, BlockStateHolder holder) {
getParent().setBlock(x, y, z, holder);
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(int x, int z) {
default BiomeType getBiome(final int x, final int z) {
return getParent().getBiome(x, z);
}
@Override
default BlockState getBlock(int x, int y, int z) {
default BlockState getBlock(final int x, final int y, final int z) {
return getParent().getBlock(x, y, z);
}
@Override
default BaseBlock getFullBlock(int x, int y, int z) {
default BaseBlock getFullBlock(final int x, final int y, final int z) {
return getParent().getFullBlock(x, y, z);
}
@Override
default void init(SingleThreadQueueExtent extent, int X, int Z) {
default void init(final V extent, final int X, final int Z) {
getParent().init(extent, X, Z);
}
@ -59,18 +58,22 @@ public interface IDelegateChunk<T extends IChunk> extends IChunk {
}
@Override
default void apply() {
getParent().apply();
default T apply() {
return getParent().apply();
}
default IChunk findParent(Class<?> clazz) {
default <T extends IChunk> T findParent(final Class<T> clazz) {
IChunk root = getParent();
if (clazz.isAssignableFrom(root.getClass())) return root;
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
while (root instanceof IDelegateChunk) {
root = ((IDelegateChunk) root).getParent();
if (clazz.isAssignableFrom(root.getClass())) return root;
if (clazz.isAssignableFrom(root.getClass())) return (T) root;
}
return null;
}
@Override
default void filter(Filter filter) {
getParent().filter(filter);
}
}

Datei anzeigen

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

Datei anzeigen

@ -1,4 +1,4 @@
package com.boydti.fawe.bukkit.v1_13.beta;
package com.boydti.fawe.beta;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -10,4 +10,6 @@ public interface IGetBlocks extends IBlocks {
BiomeType getBiome(int x, int z);
BlockState getBlock(int x, int y, int z);
void trim();
}

Datei anzeigen

@ -0,0 +1,56 @@
package com.boydti.fawe.beta;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.io.Flushable;
import java.util.concurrent.Future;
public interface IQueueExtent extends Flushable, Trimable {
void init(WorldChunkCache world);
IChunk getCachedChunk(int X, int Z);
<T> Future<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);
}
default BiomeType getBiome(final int x, final int z) {
final IChunk chunk = getCachedChunk(x >> 4, z >> 4);
return chunk.getBiome(x & 15, z & 15);
}
/**
* Return the IChunk
* @param full
* @return
*/
IChunk create(boolean full);
/**
* Wrap the chunk object (i.e. for region restrictions etc.)
* @param root
* @return wrapped chunk
*/
default IChunk wrap(IChunk root) {
return root;
}
@Override
void flush();
}

Datei anzeigen

@ -1,10 +1,10 @@
package com.boydti.fawe.bukkit.v1_13.beta;
package com.boydti.fawe.beta;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder;
public interface ISetBlocks extends IBlocks {
void setBiome(int x, int z, BiomeType biome);
boolean setBiome(int x, int y, int z, BiomeType biome);
void setBlock(int x, int y, int z, BlockStateHolder holder);
boolean setBlock(int x, int y, int z, BlockStateHolder holder);
}

Datei anzeigen

@ -0,0 +1,5 @@
package com.boydti.fawe.beta;
public interface Trimable {
boolean trim(boolean aggressive);
}

Datei anzeigen

@ -0,0 +1,122 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.beta.Trimable;
import com.boydti.fawe.object.collection.IterableThreadLocal;
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;
public abstract class QueueHandler implements Trimable {
private Map<World, WeakReference<WorldChunkCache>> chunkCache = new HashMap<>();
private IterableThreadLocal<IQueueExtent> pool = new IterableThreadLocal<IQueueExtent>() {
@Override
public IQueueExtent init() {
return create();
}
};
public WorldChunkCache getOrCreate(final World 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 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 static void apply(final Region region, final Filter filter) { // TODO not MCAFilter, but another similar class
// // 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 ForkJoinPool pool = TaskManager.IMP.getPublicForkJoinPool();
// 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] = pool.submit(new Runnable() {
// @Override
// public void run() {
// // Create a chunk that we will reuse/reset for each operation
// IChunk chunk = create(true);
//
// while (true) {
// // Get the next chunk pos
// final BlockVector2 pos;
// synchronized (chunksIter) {
// if (!chunksIter.hasNext()) return;
// pos = chunksIter.next();
// }
// final int X = pos.getX();
// final int Z = pos.getZ();
// final long pair = MathMan.pairInt(X, Z);
//
// // Initialize
// chunk.init(SingleThreadQueueExtent.this, X, Z);
//
// { // Start set
// lastPair = pair;
// lastChunk = chunk;
// }
// try {
// if (!filter.appliesChunk(X, Z)) {
// continue;
// }
// chunk = filter.applyChunk(chunk);
//
// if (chunk == null) continue;
//
// chunk.filter(filter);
//
// filter.finishChunk(chunk);
//
// chunk.apply();
// } finally
// { // End set
// lastPair = Long.MAX_VALUE;
// lastChunk = null;
// }
// }
// }
// });
// }
//
// // Join the tasks
// for (final ForkJoinTask task : tasks) {
// task.join();
// }
}
}

Datei anzeigen

@ -0,0 +1,154 @@
package com.boydti.fawe.beta.implementation;
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.boydti.fawe.util.TaskManager;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import static com.google.common.base.Preconditions.checkNotNull;
public abstract class SingleThreadQueueExtent implements IQueueExtent {
private WorldChunkCache cache;
private Thread currentThread;
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");
}
}
public WorldChunkCache getCache() {
return cache;
}
protected synchronized void reset() {
checkThread();
cache = null;
if (!chunks.isEmpty()) {
for (IChunk chunk : chunks.values()) {
chunk = chunk.getRoot();
if (chunk != null) {
chunkPool.add(chunk);
}
}
chunks.clear();
}
lastChunk = null;
lastPair = Long.MAX_VALUE;
currentThread = null;
}
@Override
public synchronized void init(final WorldChunkCache cache) {
if (cache != null) {
reset();
}
currentThread = Thread.currentThread();
checkNotNull(cache);
this.cache = cache;
}
private IChunk lastChunk;
private long lastPair = Long.MAX_VALUE;
private final Long2ObjectLinkedOpenHashMap<IChunk> chunks = new Long2ObjectLinkedOpenHashMap<>();
private final ConcurrentLinkedQueue<IChunk> chunkPool = new ConcurrentLinkedQueue<>();
@Override
public <T> ForkJoinTask<T> submit(final IChunk<T, ?> tmp) {
final ForkJoinPool pool = TaskManager.IMP.getPublicForkJoinPool();
return pool.submit(new Callable<T>() {
@Override
public T call() {
IChunk<T, ?> chunk = tmp;
T result = chunk.apply();
chunk = chunk.getRoot();
if (chunk != null) {
chunkPool.add(chunk);
}
return result;
}
});
}
@Override
public synchronized boolean trim(boolean aggressive) {
chunkPool.clear();
if (Thread.currentThread() == currentThread) {
lastChunk = null;
lastPair = Long.MAX_VALUE;
return chunks.isEmpty();
}
synchronized (this) {
return currentThread == null;
}
}
private IChunk pool(final int X, final int Z) {
IChunk next = chunkPool.poll();
if (next == null) next = create(false);
next.init(this, X, Z);
return next;
}
public final IChunk getCachedChunk(final int X, final int Z) {
final long pair = MathMan.pairInt(X, Z);
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();
if (size > Settings.IMP.QUEUE.TARGET_SIZE || MemUtil.isMemoryLimited()) {
if (size > Settings.IMP.QUEUE.PARALLEL_THREADS * 2 + 16) {
chunk = chunks.removeFirst();
submit(chunk);
}
}
chunk = pool(X, Z);
chunk = wrap(chunk);
chunks.put(pair, chunk);
lastPair = pair;
lastChunk = chunk;
return chunk;
}
@Override
public synchronized void flush() {
checkThread();
if (!chunks.isEmpty()) {
final ForkJoinTask[] tasks = new ForkJoinTask[chunks.size()];
int i = 0;
for (final IChunk chunk : chunks.values()) {
tasks[i++] = submit(chunk);
}
chunks.clear();
for (final ForkJoinTask task : tasks) {
if (task != null) task.join();
}
}
reset();
}
}

Datei anzeigen

@ -0,0 +1,62 @@
package com.boydti.fawe.beta.implementation;
import com.boydti.fawe.beta.IGetBlocks;
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;
public class WorldChunkCache implements Trimable {
protected final Long2ObjectLinkedOpenHashMap<WeakReference<IGetBlocks>> 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();
}
public synchronized IGetBlocks get(final long index, final Supplier<IGetBlocks> provider) {
final WeakReference<IGetBlocks> ref = getCache.get(index);
if (ref != null) {
final IGetBlocks blocks = ref.get();
if (blocks != null) return blocks;
}
final IGetBlocks 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<IGetBlocks>>> iter = getCache.long2ObjectEntrySet().fastIterator();
while (iter.hasNext()) {
final Long2ObjectMap.Entry<WeakReference<IGetBlocks>> entry = iter.next();
final WeakReference<IGetBlocks> value = entry.getValue();
final IGetBlocks igb = value.get();
if (igb == null) iter.remove();
else {
result = false;
if (!aggressive) return result;
synchronized (igb) {
igb.trim();
}
}
}
}
return result;
}
}

Datei anzeigen

@ -0,0 +1,7 @@
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IBlocks;
public class CharBlocks implements IBlocks {
protected char[][] blocks;
}

Datei anzeigen

@ -1,25 +1,23 @@
package com.boydti.fawe.bukkit.v1_13.beta;
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IGetBlocks;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.server.v1_13_R2.ChunkSection;
public class CharGetBlocks extends CharBlocks implements IGetBlocks {
private ChunkSection[] sections;
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
public BaseBlock getFullBlock(final int x, final int y, final int z) {
return null;
}
@Override
public BiomeType getBiome(int x, int z) {
return null;
public BiomeType getBiome(final int x, final int z) {
}
@Override
public BlockState getBlock(int x, int y, int z) {
public BlockState getBlock(final int x, final int y, final int z) {
return null;
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.boydti.fawe.bukkit.v1_13.beta;
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.ISetBlocks;
import com.sk89q.jnbt.CompoundTag;
import java.util.HashMap;

Datei anzeigen

@ -1,4 +1,6 @@
package com.boydti.fawe.bukkit.v1_13.beta;
package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IBlocks;
public class FullCharBlocks implements IBlocks {
public final boolean[] hasSections = new boolean[16];

Datei anzeigen

@ -0,0 +1,243 @@
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import com.boydti.fawe.beta.implementation.blocks.CharSetBlocks;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IGetBlocks;
import com.boydti.fawe.beta.ISetBlocks;
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
import com.boydti.fawe.beta.implementation.WorldChunkCache;
import com.boydti.fawe.util.MathMan;
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.util.function.Supplier;
public abstract class ChunkHolder<T, V extends SingleThreadQueueExtent> implements IChunk<T, V>, Supplier<IGetBlocks> {
private IGetBlocks get;
private ISetBlocks set;
private IBlockDelegate delegate;
private SingleThreadQueueExtent extent;
private int X,Z;
public ChunkHolder() {
this.delegate = NULL;
}
public ChunkHolder(IBlockDelegate delegate) {
this.delegate = delegate;
}
public final IGetBlocks cachedGet() {
if (get == null) get = newGet();
return get;
}
public final ISetBlocks cachedSet() {
if (set == null) set = set();
return set;
}
public ISetBlocks set() {
return new CharSetBlocks();
}
private IGetBlocks newGet() {
WorldChunkCache cache = extent.getCache();
cache.get(MathMan.pairInt(X, Z), this);
return new CharGetBlocks();
}
public void init(final SingleThreadQueueExtent extent, final int X, final int Z) {
this.extent = extent;
this.X = X;
this.Z = Z;
set = null;
if (delegate == BOTH) {
delegate = GET;
} else if (delegate == SET) {
delegate = NULL;
}
}
public V getExtent() {
return (V) 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.cachedSet();
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.cachedSet();
chunk.delegate = SET;
return chunk.setBlock(x, y, z, block);
}
@Override
public BiomeType getBiome(final ChunkHolder chunk, final int x, final int z) {
chunk.cachedGet();
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.cachedGet();
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.cachedGet();
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.cachedSet();
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.cachedSet();
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.getBiome(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.cachedGet();
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.cachedGet();
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.cachedGet();
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.getBiome(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

@ -1,11 +1,12 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
import com.boydti.fawe.beta.IChunk;
import com.boydti.fawe.beta.IDelegateChunk;
public class DelegateChunk<T extends IChunk> implements IDelegateChunk {
private T parent;
public DelegateChunk(T parent) {
public DelegateChunk(final T parent) {
this.parent = parent;
}
@ -13,7 +14,7 @@ public class DelegateChunk<T extends IChunk> implements IDelegateChunk {
return parent;
}
public final void setParent(T parent) {
public final void setParent(final T parent) {
this.parent = parent;
}
}
}

Datei anzeigen

@ -0,0 +1,30 @@
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, IQueueExtent queueExtent) {
super(parent);
this.queueExtent = queueExtent;
}
/**
* Submit the chunk to the queue
* @throws Throwable
*/
@Override
protected void finalize() throws Throwable {
if (getParent() != null) {
apply();
setParent(null);
}
super.finalize();
}
}

Datei anzeigen

@ -0,0 +1,23 @@
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;
public abstract class ReferenceChunk implements IDelegateChunk {
private final Reference<FinalizedChunk> ref;
public ReferenceChunk(final IChunk parent, 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,19 @@
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;
public class SoftChunk extends ReferenceChunk {
public SoftChunk(final IChunk parent, IQueueExtent queueExtent) {
super(parent, queueExtent);
}
@Override
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
return new SoftReference<>(parent);
}
}

Datei anzeigen

@ -1,17 +1,17 @@
package com.boydti.fawe.bukkit.v1_13.beta.holder;
package com.boydti.fawe.beta.implementation.holder;
import com.boydti.fawe.bukkit.v1_13.beta.IChunk;
import com.boydti.fawe.beta.IChunk;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
public class WeakChunk extends ReferenceChunk {
public WeakChunk(IChunk parent) {
public WeakChunk(final IChunk parent) {
super(parent);
}
@Override
protected Reference<FinalizedChunk> toRef(FinalizedChunk parent) {
protected Reference<FinalizedChunk> toRef(final FinalizedChunk parent) {
return new WeakReference<>(parent);
}
}