Server mode issues
DragonMaster14545 opened this issue ยท 5 comments
Minecraft Version
1.21.1
KubeJS Version
2101.7.1-build.181
Rhino Version
2101.2.6-build.56
Architectury Version
None
Forge/Fabric Version
Neoforge 21.1.89
Describe your issue
So, I wanted my friend with a vanilla client to connect to my kubejs server mode server. We got the error that they have to install neoforge, but the issue disappeared once I removed kubejs. So, I went ahead and set up a real server because we were using e4mc. The issue persistet (I had client and server running on my machine but that shouldn't be an issue). Then I installed neoforge on the client and finally got usable info (See the picture). This prevents any client from connecting unless they have kubejs installed, which Im pretty sure is not the usecase for servermode. Would be really nice if this could be fixed.
Also, a little feature request: Would it be possible to send the assets folder to the players as a server resource pack?
Thanks a lot in advance
debug_client.log
latest_client.log
latest_server.log
debug_server.log
Crash report/logs
No response
This appears to be caused by the network channels which are registered even if serverOnly mode is on:
KubeJS/src/main/java/dev/latvian/mods/kubejs/net/KubeJSNet.java
Lines 36 to 40 in 82a224d
Ok, I just downloaded the kubejs code, made the required changes (Just add !serverMode condtion) and exported it. This gave me some weird crash on the server, but when I launched the server from my ide, it worked fine but now I get this error when connecting, so it seems there are multiple things that have to be restricted to only load when server mode is off
Ok, further progress, I can now log in if I start the server from my ide. Again, idk if those modifications I did should be done as I did, but I did the following:
In the Stages interface
default void sync() {
if (getPlayer() instanceof ServerPlayer player) {
if(!CommonProperties.get().serverOnly) {
PacketDistributor.sendToPlayer(player, new SyncStagesPayload(getAll()));
}
}
}
In the KubeJSPlayerEventHandler
@SubscribeEvent(priority = EventPriority.HIGH)
public static void datapackSync(OnDatapackSyncEvent event) {
var payload = event.getPlayerList().getServer().getServerResources().managers().kjs$getServerScriptManager().serverData;
if(!CommonProperties.get().serverOnly) {
event.getRelevantPlayers().forEach(player -> PacketDistributor.sendToPlayer(player, payload));
}
}
In the base KubeJS mod class
if(!CommonProperties.get().serverOnly) {
KubeJSIngredients.REGISTRY.register(bus);
KubeJSFluidIngredients.REGISTRY.register(bus);
KubeJSCreativeTabs.REGISTRY.register(bus);
KubeJSRuleTests.REGISTRY.register(bus);
KubeJSHolderSets.REGISTRY.register(bus);
}
This fixes it if I launch the server from the ide, allowing connections from vanilla clients, but I get a startup crash when launching a normal server with my custom build
debug.log
This was required to fix a crash when clicking like anywhere:
In MinecraftClientKJS class
@HideFromJS
default void kjs$startAttack0() {
if (ItemEvents.FIRST_LEFT_CLICKED.hasListeners()) {
var player = kjs$self().player;
var stack = player.getItemInHand(InteractionHand.MAIN_HAND);
var key = stack.getItem().kjs$getKey();
if (ItemEvents.FIRST_LEFT_CLICKED.hasListeners(key)) {
ItemEvents.FIRST_LEFT_CLICKED.post(ScriptType.CLIENT, key, new ItemClickedKubeEvent(player, InteractionHand.MAIN_HAND, stack));
}
}
if(!CommonProperties.get().serverOnly) {
PacketDistributor.sendToServer(new FirstClickPayload(0));
}
}
@HideFromJS
default void kjs$startUseItem0() {
if (ItemEvents.FIRST_RIGHT_CLICKED.hasListeners()) {
var player = kjs$self().player;
for (var hand : InteractionHand.values()) {
var stack = player.getItemInHand(hand);
var key = stack.getItem().kjs$getKey();
if (ItemEvents.FIRST_RIGHT_CLICKED.hasListeners(key)) {
ItemEvents.FIRST_RIGHT_CLICKED.post(ScriptType.CLIENT, key, new ItemClickedKubeEvent(player, hand, stack));
}
}
}
if(!CommonProperties.get().serverOnly) {
PacketDistributor.sendToServer(new FirstClickPayload(1));
}
}