feat: расширена отладка & испавлена ошибка BlockSource при EntityRemoved & исправлено поломка SocketServer(not tested)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.reider745.api;
|
||||
|
||||
import cn.nukkit.Server;
|
||||
import cn.nukkit.event.Event;
|
||||
import cn.nukkit.level.Level;
|
||||
import com.reider745.api.hooks.HookController;
|
||||
@@ -43,11 +44,9 @@ public class CallbackHelper {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
while (Server.getInstance().isRunning()) {
|
||||
synchronized (applys) {
|
||||
Iterator<ICallbackApply> it = applys.iterator();
|
||||
while (it.hasNext())
|
||||
it.next().apply();
|
||||
for (ICallbackApply apply : applys) apply.apply();
|
||||
applys.clear();
|
||||
}
|
||||
try {
|
||||
@@ -55,6 +54,8 @@ public class CallbackHelper {
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
Logger.warning("Disable thread: "+getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +174,7 @@ public class CallbackHelper {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void setValueForCurrent(Object value) {
|
||||
Thread thread = Thread.currentThread();
|
||||
final Thread thread = Thread.currentThread();
|
||||
if (thread instanceof ThreadCustomValue custom) {
|
||||
try {
|
||||
custom.value = value;
|
||||
@@ -184,9 +185,9 @@ public class CallbackHelper {
|
||||
}
|
||||
|
||||
public static Level getForCurrentThread() {
|
||||
Thread thread = Thread.currentThread();
|
||||
if (thread instanceof ThreadCustomValue threadCallback && threadCallback.getValue() instanceof Level) {
|
||||
return (Level) threadCallback.getValue();
|
||||
final Thread thread = Thread.currentThread();
|
||||
if (thread instanceof ThreadCustomValue threadCallback && threadCallback.getValue() instanceof Level level) {
|
||||
return level;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ public class EventListener implements Listener {
|
||||
final Entity entity = event.getEntity();
|
||||
|
||||
EntityMotion.remove(entity);
|
||||
NativeCallback.onEntityRemoved(EntityMethod.getIdForEntity(entity));
|
||||
if(entity.level != null) NativeCallback.onEntityRemoved(EntityMethod.getIdForEntity(entity));
|
||||
}
|
||||
|
||||
public static int convertDamageCauseToEnum(DamageCause cause) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import cn.nukkit.math.Vector3;
|
||||
import com.reider745.api.CallbackHelper;
|
||||
import com.reider745.world.dimensions.NoiseOctaveMethods;
|
||||
import com.zhekasmirnov.apparatus.mcpe.NativeBlockSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GenerationUtilsMethods {
|
||||
@@ -64,7 +65,7 @@ public class GenerationUtilsMethods {
|
||||
private static NukkitRandom rand = null;
|
||||
|
||||
public static void generateOreNative(int x, int y, int z, int id, int data, int clusterSize, boolean whitelist, int[] blockIds, int seed){
|
||||
Level level = CallbackHelper.getForCurrentThread();
|
||||
final Level level = CallbackHelper.getForCurrentThread();
|
||||
|
||||
if(level == null) throw new RuntimeException("Region null");
|
||||
if(rand == null) rand = new NukkitRandom();
|
||||
|
||||
@@ -65,7 +65,7 @@ public class NativeBlockSource {
|
||||
|
||||
public static NativeBlockSource getCurrentWorldGenRegion() {
|
||||
Level level = CallbackHelper.getForCurrentThread();
|
||||
if(level == null) Server.getInstance().getDefaultLevel();
|
||||
if(level == null) level = Server.getInstance().getDefaultLevel();
|
||||
return level != null ? new NativeBlockSource(level, false) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,10 +86,10 @@ public class SocketServer {
|
||||
}
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
Logger.error("socket server error", "error in creating channel", exception);
|
||||
Logger.error("socket server error", "error in creating channel, sleep socket", exception);
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,16 +83,12 @@ public class WorldGen {
|
||||
}
|
||||
|
||||
private static int dimensionIdToGenerationMode(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return MODE_SURFACE;
|
||||
case 1:
|
||||
return MODE_NETHER;
|
||||
case 2:
|
||||
return MODE_END;
|
||||
default:
|
||||
return MODE_CUSTOM;
|
||||
}
|
||||
return switch (id) {
|
||||
case 0 -> MODE_SURFACE;
|
||||
case 1 -> MODE_NETHER;
|
||||
case 2 -> MODE_END;
|
||||
default -> MODE_CUSTOM;
|
||||
};
|
||||
}
|
||||
|
||||
public static void generateChunk(int x, int z, int level) {
|
||||
@@ -103,15 +99,18 @@ public class WorldGen {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int lvl : allLevels) {
|
||||
generateChunk(x, z, dimension, lvl);
|
||||
}
|
||||
|
||||
// if feature is not supported, call every generation level at once
|
||||
if (!MinecraftVersions.getCurrent()
|
||||
.isFeatureSupported(MinecraftVersion.FEATURE_VANILLA_WORLD_GENERATION_LEVELS)) {
|
||||
/*if (!MinecraftVersions.getCurrent().isFeatureSupported(MinecraftVersion.FEATURE_VANILLA_WORLD_GENERATION_LEVELS)) {
|
||||
for (int lvl : allLevels) {
|
||||
generateChunk(x, z, dimension, lvl);
|
||||
}
|
||||
} else {
|
||||
generateChunk(x, z, dimension, level);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public static void generateChunk(int x, int z, int dimensionId, int level) {
|
||||
|
||||
Reference in New Issue
Block a user