Jump to content

Recommended Posts

Posted (edited)

Hi !

I'm using SimpleImpl to send data from the server to the client.

I have to send 2 different messages (in fact, the same message containing different informations) approximatively at the same time to all players.

But players receive two times the same message.

If I pause the server thread after the first message is sent, both messages are correctly received. So I conclude that there's not enough time between the moments where messages are sent.
Do you know how can I fix that ?

Edited by Franckyi
Posted (edited)

One solution could be to change the message to send a set of data instead of only one data per message. If someone has a better solution, please tell me.

And also, that's strange that I can't send two messages in a too short period of time.

[EDIT] My solution works.

Edited by Franckyi
Posted (edited)

I haven't really checked if it was correct or not, but with my new message it works.

How do I send a message to the players tracking the chunk ?

And also, if player 1 goes far away (not tracking the chunk), then player 2 updates the block, then player 1 comes back, is the data sent automatically to player 1 when he loads the chunk ? Or I have to detect and send the data to the client ?

 

Edited by Franckyi
Posted (edited)

Thanks !
So this should work ?


BlockRedstoneController::breakBlock (everything is called server side)

WorldServer worldServer = (WorldServer) world;
for (EntityPlayer player : worldServer.playerEntities) {
	EntityPlayerMP playerMP = (EntityPlayerMP) player;
	if (worldServer.getPlayerChunkMap() {
		.getEntry(world.getChunkFromBlockCoords(pos).x, world.getChunkFromBlockCoords(pos).z)
		.containsPlayer(playerMP))
			PacketHandler.INSTANCE.sendTo(new UpdateRedstoneControllerMessage(updateControllers), playerMP);
    }
}

(and the same for BlockRedstoneSwitch)

 

EventHandler (I don't know if this event is fired on the server, on client or on both)

@SubscribeEvent
public void onChunkWatch(ChunkWatchEvent.Watch event) {
	WorldServer world = event.getPlayer().getServerWorld();
	if (!world.isRemote) {
		for (TileEntity te : world.loadedTileEntityList) {
			if (event.getChunk().equals(world.getChunkFromBlockCoords(te.getPos()).getPos())) {
				if (te instanceof TileEntityRedstoneSwitch) {
					PacketHandler.INSTANCE.sendTo(new UpdateRedstoneSwitchMessage(te.getPos(),
							te.getCapability(RedstoneSwitchProvider.SWITCH_CAP, null).getSwitch()), event.getPlayer());
				} else if (te instanceof TileEntityRedstoneController) {
					PacketHandler.INSTANCE.sendTo(new UpdateRedstoneControllerMessage(te.getPos(),
							te.getCapability(RedstoneControllerProvider.CONTROLLER_CAP, null).getController()), event.getPlayer());
				}
			}
		}
	}
}

 

 

 

Edited by Franckyi
Posted

Okay so everything seems to be fine. But I have another problem also linked to networking : my mod can't run on the server.

Crash Report

It fails when it registers a message that is handled on the client side. But I must register it on both sides anyway, right ?

I really don't know where does it try to load the WorldClient class.

Is it linked to my special PacketHandler class ?

 

public class PacketHandler {

	public static abstract class ClientHandler<REQ extends IMessage> extends CommonHandler<REQ> {

		@Override
		public IMessage onMessage(REQ message, MessageContext ctx) {
			super.onMessage(message, ctx);
			this.world = Minecraft.getMinecraft().world;
			this.mainThread = Minecraft.getMinecraft();
			this.mainThread.addScheduledTask(this);
			return null;
		}

	}

	public static abstract class CommonHandler<REQ extends IMessage>
			implements IMessageHandler<REQ, IMessage>, Runnable {

		protected World world;
		protected IThreadListener mainThread;
		protected REQ message;
		protected MessageContext ctx;

		@Override
		public IMessage onMessage(REQ message, MessageContext ctx) {
			this.message = message;
			this.ctx = ctx;
			return null;
		}

	}

	public static abstract class ServerHandler<REQ extends IMessage> extends CommonHandler<REQ> {

		@Override
		public IMessage onMessage(REQ message, MessageContext ctx) {
			super.onMessage(message, ctx);
			this.world = ctx.getServerHandler().player.world;
			this.mainThread = (WorldServer) this.world;
			this.mainThread.addScheduledTask(this);
			return null;
		}

	}

	public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(ModReference.MODID);

}

 

Client-side Message Handlers extends PacketHandler.ClientHandler whereas Server-side Message Handlers extends PacketHandler.ServerHandler.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I also just tried with iron's spellbooks removed, since that seemed related, but i am still having the same problem, even in newly created worlds. https://mclo.gs/AtrAfaj 
    • My Gradle Project for my Minecraft mod isn't building. Terminal: * Where: Settings file 'C:\Users\csonn\OneDrive\Desktop\fusionlucky\settings.gradle' line: 2 * What went wrong: Could not compile settings file 'C:\Users\csonn\OneDrive\Desktop\fusionlucky\settings.gradle'. > startup failed:   settings file 'C:\Users\csonn\OneDrive\Desktop\fusionlucky\settings.gradle': 2: The pluginManagement {} block must appear before any other statements in the script.   For more information on the pluginManagement {} block, please refer to https://docs.gradle.org/9.0.0/userguide/plugins.html#sec:plugin_management in the Gradle documentation.    @ line 2, column 1.      pluginManagement {      ^   1 error * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to generate a Build Scan (Powered by Develocity). > Get more help at https://help.gradle.org.   Setting.Gradle File:   rootProject.name = 'fusion-lucky-block' pluginManagement {     repositories {         gradlePluginPortal()         maven { url "https://maven.minecraftforge.net/" }         mavenCentral()     } }
    • no change still. here's a new log  https://mclo.gs/RXwiZmn 
    • Whenever I go to build my it says "Build failed in " how many seconds   Here is what is said in my terminal * Where: Build file 'C:\Users\csonn\OneDrive\Desktop\fusionlucky\build.gradle' line: 3 * What went wrong: Plugin [id: 'net.minecraftforge.gradle', version: '6.1.51'] was not found in any of the following sources: - Gradle Core Plugins (plugin is not in 'org.gradle' namespace) - Included Builds (No included builds contain this plugin) - Plugin Repositories (could not resolve plugin artifact 'net.minecraftforge.gradle:net.minecraftforge.gradle.gradle.plugin:6.1.51')   Searched in the following repositories:     Gradle Central Plugin Repository     MinecraftForge(https://maven.minecraftforge.net/) * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Get more help at https://help.gradle.org.   Here is what is in my build.gradle file plugins {     id 'java'     id 'net.minecraftforge.gradle' version '6.1+' }   group = 'io.github.csonnic03.fusionlucky' version = '1.0.0' archivesBaseName = 'fusionlucky'   java {     toolchain {         languageVersion = JavaLanguageVersion.of(17)     } }   repositories {     mavenCentral()     maven {         name "forgeMaven"         url "https://maven.minecraftforge.net/<repository>" } }   dependencies {     minecraft 'net.minecraftforge:forge:1.20.1-47.1.0' }   minecraft {     mappings channel: 'official', version: '1.20.1'     runs {         client {             workingDirectory project.file('run')         }         server {             workingDirectory project.file('run')         }     } }   tasks.withType(JavaCompile) {     options.encoding = 'UTF-8' }   jar {     manifest {         attributes(             "Specification-Title": "Fusion Lucky Block",             "Specification-Vendor": "example",             "Implementation-Title": project.name,             "Implementation-Version": project.version,             "Implementation-Vendor": "example",             "ModLauncher-TargetFMLVersion": "[47,)"         )     } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.