geforkt von Mirrors/FastAsyncWorldEdit
Ursprung
e0e66ce2db
Commit
79c23e06c3
@ -55,6 +55,7 @@ import com.sk89q.worldedit.world.block.BlockTypesCache;
|
|||||||
import com.sk89q.worldedit.world.entity.EntityType;
|
import com.sk89q.worldedit.world.entity.EntityType;
|
||||||
import com.sk89q.worldedit.world.item.ItemType;
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||||
|
import io.papermc.lib.PaperLib;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.WritableRegistry;
|
import net.minecraft.core.WritableRegistry;
|
||||||
@ -663,17 +664,11 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RelighterFactory getRelighterFactory() {
|
public RelighterFactory getRelighterFactory() {
|
||||||
try {
|
if (PaperLib.isPaper()) {
|
||||||
Class.forName("ca.spottedleaf.starlight.common.light.StarLightEngine");
|
return new PaperweightStarlightRelighterFactory();
|
||||||
if (PaperweightStarlightRelighter.isUsable()) {
|
} else {
|
||||||
return new PaperweightStarlightRelighterFactory();
|
return new NMSRelighterFactory();
|
||||||
}
|
|
||||||
} catch (ThreadDeath td) {
|
|
||||||
throw td;
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return new NMSRelighterFactory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,16 +14,12 @@ import it.unimi.dsi.fastutil.longs.LongIterator;
|
|||||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
import net.minecraft.server.MCUtil;
|
import net.minecraft.server.MCUtil;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ThreadedLevelLightEngine;
|
|
||||||
import net.minecraft.server.level.TicketType;
|
import net.minecraft.server.level.TicketType;
|
||||||
import net.minecraft.util.Unit;
|
import net.minecraft.util.Unit;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
|
||||||
import java.lang.invoke.MethodHandles;
|
|
||||||
import java.lang.invoke.MethodType;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,7 +31,6 @@ import java.util.function.IntConsumer;
|
|||||||
|
|
||||||
public class PaperweightStarlightRelighter implements Relighter {
|
public class PaperweightStarlightRelighter implements Relighter {
|
||||||
|
|
||||||
public static final MethodHandle RELIGHT;
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
private static final int CHUNKS_PER_BATCH = 1024; // 32 * 32
|
private static final int CHUNKS_PER_BATCH = 1024; // 32 * 32
|
||||||
private static final int CHUNKS_PER_BATCH_SQRT_LOG2 = 5; // for shifting
|
private static final int CHUNKS_PER_BATCH_SQRT_LOG2 = 5; // for shifting
|
||||||
@ -43,26 +38,6 @@ public class PaperweightStarlightRelighter implements Relighter {
|
|||||||
private static final TicketType<Unit> FAWE_TICKET = TicketType.create("fawe_ticket", (a, b) -> 0);
|
private static final TicketType<Unit> FAWE_TICKET = TicketType.create("fawe_ticket", (a, b) -> 0);
|
||||||
private static final int LIGHT_LEVEL = MCUtil.getTicketLevelFor(ChunkStatus.LIGHT);
|
private static final int LIGHT_LEVEL = MCUtil.getTicketLevelFor(ChunkStatus.LIGHT);
|
||||||
|
|
||||||
static {
|
|
||||||
MethodHandle tmp = null;
|
|
||||||
try {
|
|
||||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
|
||||||
tmp = lookup.findVirtual(
|
|
||||||
ThreadedLevelLightEngine.class,
|
|
||||||
"relight",
|
|
||||||
MethodType.methodType(
|
|
||||||
int.class, // return type
|
|
||||||
// params
|
|
||||||
Set.class,
|
|
||||||
Consumer.class,
|
|
||||||
IntConsumer.class
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
|
||||||
LOGGER.error("Failed to locate 'relight' method in ThreadedLevelLightEngine. Is everything up to date?", e);
|
|
||||||
}
|
|
||||||
RELIGHT = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ServerLevel serverLevel;
|
private final ServerLevel serverLevel;
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
@ -76,10 +51,6 @@ public class PaperweightStarlightRelighter implements Relighter {
|
|||||||
this.delegate = new NMSRelighter(queue);
|
this.delegate = new NMSRelighter(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUsable() {
|
|
||||||
return RELIGHT != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addChunk(int cx, int cz, byte[] skipReason, int bitmask) {
|
public boolean addChunk(int cx, int cz, byte[] skipReason, int bitmask) {
|
||||||
areaLock.lock();
|
areaLock.lock();
|
||||||
@ -169,14 +140,9 @@ public class PaperweightStarlightRelighter implements Relighter {
|
|||||||
IntConsumer processCallback
|
IntConsumer processCallback
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
int unused = (int) RELIGHT.invokeExact(
|
serverLevel.getChunkSource().getLightEngine().relight(coords, chunkCallback, processCallback);
|
||||||
serverLevel.getChunkSource().getLightEngine(),
|
} catch (Exception e) {
|
||||||
coords,
|
LOGGER.error("Error occurred on relighting", e);
|
||||||
chunkCallback, // callback per chunk
|
|
||||||
processCallback // callback for all chunks
|
|
||||||
);
|
|
||||||
} catch (Throwable throwable) {
|
|
||||||
LOGGER.error("Error occurred on relighting", throwable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,17 +653,11 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RelighterFactory getRelighterFactory() {
|
public RelighterFactory getRelighterFactory() {
|
||||||
try {
|
if (PaperLib.isPaper()) {
|
||||||
Class.forName("ca.spottedleaf.starlight.common.light.StarLightEngine");
|
return new PaperweightStarlightRelighterFactory();
|
||||||
if (PaperweightStarlightRelighter.isUsable()) {
|
} else {
|
||||||
return new PaperweightStarlightRelighterFactory();
|
return new NMSRelighterFactory();
|
||||||
}
|
|
||||||
} catch (ThreadDeath td) {
|
|
||||||
throw td;
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return new NMSRelighterFactory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,16 +14,12 @@ import it.unimi.dsi.fastutil.longs.LongIterator;
|
|||||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
import net.minecraft.server.level.ChunkMap;
|
import net.minecraft.server.level.ChunkMap;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ThreadedLevelLightEngine;
|
|
||||||
import net.minecraft.server.level.TicketType;
|
import net.minecraft.server.level.TicketType;
|
||||||
import net.minecraft.util.Unit;
|
import net.minecraft.util.Unit;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
|
||||||
import java.lang.invoke.MethodHandles;
|
|
||||||
import java.lang.invoke.MethodType;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,7 +31,6 @@ import java.util.function.IntConsumer;
|
|||||||
|
|
||||||
public class PaperweightStarlightRelighter implements Relighter {
|
public class PaperweightStarlightRelighter implements Relighter {
|
||||||
|
|
||||||
public static final MethodHandle RELIGHT;
|
|
||||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||||
private static final int CHUNKS_PER_BATCH = 1024; // 32 * 32
|
private static final int CHUNKS_PER_BATCH = 1024; // 32 * 32
|
||||||
private static final int CHUNKS_PER_BATCH_SQRT_LOG2 = 5; // for shifting
|
private static final int CHUNKS_PER_BATCH_SQRT_LOG2 = 5; // for shifting
|
||||||
@ -43,26 +38,6 @@ public class PaperweightStarlightRelighter implements Relighter {
|
|||||||
private static final TicketType<Unit> FAWE_TICKET = TicketType.create("fawe_ticket", (a, b) -> 0);
|
private static final TicketType<Unit> FAWE_TICKET = TicketType.create("fawe_ticket", (a, b) -> 0);
|
||||||
private static final int LIGHT_LEVEL = ChunkMap.MAX_VIEW_DISTANCE + ChunkStatus.getDistance(ChunkStatus.LIGHT);
|
private static final int LIGHT_LEVEL = ChunkMap.MAX_VIEW_DISTANCE + ChunkStatus.getDistance(ChunkStatus.LIGHT);
|
||||||
|
|
||||||
static {
|
|
||||||
MethodHandle tmp = null;
|
|
||||||
try {
|
|
||||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
|
||||||
tmp = lookup.findVirtual(
|
|
||||||
ThreadedLevelLightEngine.class,
|
|
||||||
"relight",
|
|
||||||
MethodType.methodType(
|
|
||||||
int.class, // return type
|
|
||||||
// params
|
|
||||||
Set.class,
|
|
||||||
Consumer.class,
|
|
||||||
IntConsumer.class
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
|
||||||
LOGGER.error("Failed to locate 'relight' method in ThreadedLevelLightEngine. Is everything up to date?", e);
|
|
||||||
}
|
|
||||||
RELIGHT = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ServerLevel serverLevel;
|
private final ServerLevel serverLevel;
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
@ -76,10 +51,6 @@ public class PaperweightStarlightRelighter implements Relighter {
|
|||||||
this.delegate = new NMSRelighter(queue);
|
this.delegate = new NMSRelighter(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUsable() {
|
|
||||||
return RELIGHT != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addChunk(int cx, int cz, byte[] skipReason, int bitmask) {
|
public boolean addChunk(int cx, int cz, byte[] skipReason, int bitmask) {
|
||||||
areaLock.lock();
|
areaLock.lock();
|
||||||
@ -169,14 +140,9 @@ public class PaperweightStarlightRelighter implements Relighter {
|
|||||||
IntConsumer processCallback
|
IntConsumer processCallback
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
int unused = (int) RELIGHT.invokeExact(
|
serverLevel.getChunkSource().getLightEngine().relight(coords, chunkCallback, processCallback);
|
||||||
serverLevel.getChunkSource().getLightEngine(),
|
} catch (Exception e) {
|
||||||
coords,
|
LOGGER.error("Error occurred on relighting", e);
|
||||||
chunkCallback, // callback per chunk
|
|
||||||
processCallback // callback for all chunks
|
|
||||||
);
|
|
||||||
} catch (Throwable throwable) {
|
|
||||||
LOGGER.error("Error occurred on relighting", throwable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren