Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server mode issues #933

Open
DragonMaster14545 opened this issue Dec 15, 2024 · 5 comments
Open

Server mode issues #933

DragonMaster14545 opened this issue Dec 15, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@DragonMaster14545
Copy link

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
error

Crash report/logs

No response

@DragonMaster14545 DragonMaster14545 added the bug Something isn't working label Dec 15, 2024
@ChiefArug
Copy link
Contributor

This appears to be caused by the network channels which are registered even if serverOnly mode is on:

@SubscribeEvent
static void register(RegisterPayloadHandlersEvent event) {
var reg = event.registrar("1");
reg.playToClient(WEB_SERVER_JSON_UPDATE, WebServerUpdateJSONPayload.STREAM_CODEC, WebServerUpdateJSONPayload::handle);

@DragonMaster14545
Copy link
Author

So its an easy fix?

@DragonMaster14545
Copy link
Author

image
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

@DragonMaster14545
Copy link
Author

DragonMaster14545 commented Dec 15, 2024

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

@DragonMaster14545
Copy link
Author

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

	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants