Skip to content

Commit

Permalink
feat: расширена отладка & испавлена ошибка BlockSource при EntityRemo…
Browse files Browse the repository at this point in the history
…ved & исправлено поломка SocketServer(not tested)
  • Loading branch information
Reider745 committed Oct 31, 2024
1 parent f92a988 commit a7381cd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
17 changes: 9 additions & 8 deletions src/main/java/com/reider745/api/CallbackHelper.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,18 +44,18 @@ public void add(ICallbackApply apply) {

@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 {
sleep(10);
} catch (InterruptedException e) {
}
}

Logger.warning("Disable thread: "+getName());
}
}

Expand Down Expand Up @@ -173,7 +174,7 @@ public static boolean isPrevent() {

@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;
Expand All @@ -184,9 +185,9 @@ public static void setValueForCurrent(Object value) {
}

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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/reider745/event/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void onEntityDespawn(EntityDespawnEvent event) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.reider745.api.CallbackHelper;
import com.reider745.world.dimensions.NoiseOctaveMethods;
import com.zhekasmirnov.apparatus.mcpe.NativeBlockSource;

import java.util.ArrayList;

public class GenerationUtilsMethods {
Expand Down Expand Up @@ -64,7 +65,7 @@ private static boolean isReplace(int[] ids, int id, boolean whitelist){
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static NativeBlockSource getDefaultForLevel(String name) {

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public void start(int port) throws IOException {
}
}
} 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,12 @@ private static void generateChunkByLevelAndMode(int chunkX, int chunkZ, int dime
}

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) {
Expand All @@ -103,15 +99,18 @@ public static void generateChunk(int x, int z, int level) {
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) {
Expand Down

0 comments on commit a7381cd

Please sign in to comment.