Possible fix for VS entity brushes

close #564
close #565
close #566
This commit is contained in:
Jesse Boyd 2017-06-07 07:34:11 +10:00
parent 8b9c1b7563
commit b3e0125c71
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
6 changed files with 100 additions and 18 deletions

View File

@ -85,13 +85,13 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
keepLoaded.put(pair, Long.MAX_VALUE);
if (world.isChunkLoaded(cx, cz)) {
Chunk chunk = world.getChunkAt(cx, cz);
ChunkSnapshot snapshot = chunk.getChunkSnapshot(false, true, false);
if (originalKeep != null) {
keepLoaded.put(pair, originalKeep);
} else {
keepLoaded.remove(pair);
}
return chunk.getChunkSnapshot(false, true, false);
return snapshot;
} else {
keepLoaded.remove(pair);
return null;

View File

@ -1,5 +1,6 @@
package com.boydti.fawe.bukkit.wrapper;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.FaweQueue;
import java.util.Collection;
import java.util.List;
@ -22,9 +23,9 @@ public class AsyncBlock implements Block {
public final int y;
public final int x;
public final FaweQueue queue;
public final World world;
public final AsyncWorld world;
public AsyncBlock(World world, FaweQueue queue, int x, int y, int z) {
public AsyncBlock(AsyncWorld world, FaweQueue queue, int x, int y, int z) {
this.world = world;
this.queue = queue;
this.x = x;
@ -64,17 +65,17 @@ public class AsyncBlock implements Block {
@Override
public byte getLightLevel() {
throw new UnsupportedOperationException("Not implemented yet");
return (byte) queue.getLight(x, y, z);
}
@Override
public byte getLightFromSky() {
throw new UnsupportedOperationException("Not implemented yet");
return (byte) queue.getSkyLight(x, y, z);
}
@Override
public byte getLightFromBlocks() {
throw new UnsupportedOperationException("Not implemented yet");
return (byte) queue.getEmmittedLight(x, y, z);
}
@Override
@ -172,12 +173,13 @@ public class AsyncBlock implements Block {
@Override
public Biome getBiome() {
throw new UnsupportedOperationException("NOT IMPLEMENTED");
return world.getAdapter().getBiome(queue.getBiomeId(x, z));
}
@Override
public void setBiome(Biome bio) {
int id = world.getAdapter().getBiomeId(bio);
queue.setBiome(x, z, FaweCache.getBiome(id));
}
@Override
@ -217,7 +219,7 @@ public class AsyncBlock implements Block {
@Override
public boolean isLiquid() {
return false;
return FaweCache.isLiquid(getTypeId());
}
@Override

View File

@ -1,7 +1,9 @@
package com.boydti.fawe.bukkit.wrapper;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.TaskManager;
import org.bukkit.Chunk;
@ -13,13 +15,13 @@ import org.bukkit.entity.Entity;
public class AsyncChunk implements Chunk {
private final World world;
private final AsyncWorld world;
private final int z;
private final int x;
private final FaweQueue queue;
public AsyncChunk(World world, FaweQueue queue, int x, int z) {
this.world = world instanceof AsyncWorld ? world : new AsyncWorld(world, true);
this.world = world instanceof AsyncWorld ? (AsyncWorld) world : new AsyncWorld(world, true);
this.queue = queue;
this.x = x;
this.z = z;
@ -61,22 +63,71 @@ public class AsyncChunk implements Chunk {
@Override
public ChunkSnapshot getChunkSnapshot() {
throw new UnsupportedOperationException("NOT IMPLEMENTED");
return getChunkSnapshot(false, true, false);
}
@Override
public ChunkSnapshot getChunkSnapshot(boolean includeMaxblocky, boolean includeBiome, boolean includeBiomeTempRain) {
throw new UnsupportedOperationException("NOT IMPLEMENTED");
if (Thread.currentThread() == Fawe.get().getMainThread()) {
return world.getChunkAt(x, z).getChunkSnapshot(includeMaxblocky, includeBiome, includeBiomeTempRain);
}
return whenLoaded(new RunnableVal<ChunkSnapshot>() {
@Override
public void run(ChunkSnapshot value) {
this.value = world.getChunkAt(x, z).getChunkSnapshot(includeBiome, includeBiome, includeBiomeTempRain);
}
});
}
private <T> T whenLoaded(RunnableVal<T> task) {
if (Thread.currentThread() == Fawe.get().getMainThread()) {
task.run();
return task.value;
}
if (queue instanceof BukkitQueue_0) {
BukkitQueue_0 bq = (BukkitQueue_0) queue;
if (world.isChunkLoaded(x, z)) {
long pair = MathMan.pairInt(x, z);
Long originalKeep = bq.keepLoaded.get(pair);
bq.keepLoaded.put(pair, Long.MAX_VALUE);
if (world.isChunkLoaded(x, z)) {
task.run();
if (originalKeep != null) {
bq.keepLoaded.put(pair, originalKeep);
} else {
bq.keepLoaded.remove(pair);
}
return task.value;
}
}
}
return TaskManager.IMP.sync(task);
}
@Override
public Entity[] getEntities() {
throw new UnsupportedOperationException("NOT IMPLEMENTED");
if (!isLoaded()) {
return new Entity[0];
}
return whenLoaded(new RunnableVal<Entity[]>() {
@Override
public void run(Entity[] value) {
world.getChunkAt(x, z).getEntities();
}
});
}
@Override
public BlockState[] getTileEntities() {
throw new UnsupportedOperationException("NOT IMPLEMENTED");
if (!isLoaded()) {
return new BlockState[0];
}
return TaskManager.IMP.sync(new RunnableVal<BlockState[]>() {
@Override
public void run(BlockState[] value) {
this.value = world.getChunkAt(x, z).getTileEntities();
}
});
}
@Override

View File

@ -1043,4 +1043,8 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue
public Set<String> getListeningPluginChannels() {
return parent.getListeningPluginChannels();
}
public BukkitImplAdapter getAdapter() {
return adapter;
}
}

View File

@ -295,6 +295,18 @@ public class FaweCache {
}
}
public static boolean isLiquid(int id) {
switch (id) {
case 8:
case 9:
case 10:
case 11:
return true;
default:
return false;
}
}
public static LightType getLight(int id) {
switch (id) { // Lighting
case 0:

View File

@ -11,6 +11,7 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.MaskedFaweQueue;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.changeset.FaweChangeSet;
import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
@ -325,7 +326,19 @@ public class Sniper {
performerBrush.initP(snipeData);
}
boolean result = brush.perform(snipeAction, snipeData, targetBlock, lastBlock);
switch (brush.getClass().getSimpleName()) {
case "JockeyBrush":
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
brush.perform(snipeAction, snipeData, targetBlock, lastBlock);
}
});
break;
default:
brush.perform(snipeAction, snipeData, targetBlock, lastBlock);
break;
}
if (Fawe.isMainThread()) {
SetQueue.IMP.flush(changeQueue);
} else {