Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED] Adding tasks for different side than original(CLIENT-SERVER) by using NetworkEvent.Context


Mr Bonobo
 Share

Recommended Posts

What is the new way of adding task to work queue?

What i want to do in old way:

public static void handle(Packet message, Supplier<NetworkEvent.Context> contextSupplier) {
FMLCommonHandler.instance().getWorldThread(contextSupplier.netHandler).addScheduledTask(() ->

New way:

public static void handle(Packetmessage, Supplier<NetworkEvent.Context> contextSupplier) {
      contextSupplier.get().enqueueWork(() -> {

If contexSupplier is CLIENT, it will add task on CLIENT. So what should i do to add task on DEDICATED_SERVER, even though contextSupplier is CLIENT?

Edited by Mr Bonobo
Link to comment
Share on other sites

Ok, I somewhat managed to make it work in different way by accessing capability values with:

 

public static void handle(PacketTriggerElectricGen message, Supplier<NetworkEvent.Context> contextSupplier) {
contextSupplier.get().enqueueWork(() -> {
    contextSupplier.get().getSender().getServerWorld().getTileEntity(message.blockPos).
            getCapability(new UtilCapabilities().UTIL_CAP).ifPresent(st -> {

And context shouldnt be in CLIENT-side, because this packet is triggered by sendToServer(new etc...) from CLIENTside, only sender should be a CLIENT. Even though i tested with DistExecutor which side it is, and it shows its always a CLIENT, but maybe its SERVER after all if I managed to access SERVER side capability values.

Link to comment
Share on other sites

You are the confusing the concepts of distribution (dedicated server vs the client launched from the launcher, this is what DistExecutor checks) vs logical side (server, including integrated server used in singleplayer, vs client, the thing that renders the game and accepts inputs).

What matters here is the logical side, which is usually accessible using World#isRemote (true on the client). The context also tells you the direction (it is on the network thread, this is why you need to "enqueueWork" and also why you don't have a world here) using NetworkEvent.Context#getDirection.

  • Thanks 1
Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

You are the confusing the concepts of distribution (dedicated server vs the client launched from the launcher, this is what DistExecutor checks) vs logical side (server, including integrated server used in singleplayer, vs client, the thing that renders the game and accepts inputs).

What matters here is the logical side, which is usually accessible using World#isRemote (true on the client). The context also tells you the direction (it is on the network thread, this is why you need to "enqueueWork" and also why you don't have a world here) using NetworkEvent.Context#getDirection.

Wow! Very good and full-explanitory post. It solved probably all my questions. Only one question came from it: if i create packet, which is sent from a SERVER and handled by a CLIENT, I dont need to use enqueueWork then, or I should add this scheduled task always to prevent bugs/overlapping even on CLIENT side??

Link to comment
Share on other sites

Just now, Mr Bonobo said:

if i create packet, which is sent from a SERVER and handled by a CLIENT, I dont need to use enqueueWork

Yes, you do. Packets are received on the network thread always, that's why you need enqueueWork (you can read the name as "doThisOnMainThread"). Most of Minecraft is not thread-safe, which is why you need to schedule your code to run on the main thread if you want to do anything meaningful from your packet.

  • Thanks 1
Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Yes, you do. Packets are received on the network thread always, that's why you need enqueueWork (you can read the name as "doThisOnMainThread"). Most of Minecraft is not thread-safe, which is why you need to schedule your code to run on the main thread if you want to do anything meaningful from your packet.

A many thanks to you! :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • look at createTrivialBlock(a,b); on package net.minecraft.data.models.BlockModelGenerators; (i don't know how it works but i think it may give u a hint)
    • Whenever i logout and back-in in the game, the data resets to its define state (how can i save the entity data to be persistent)   the code words, data is used flawlessly, but just doesn't save through game exit public class TyBoss extends Monster{ public static final EntityDataAccessor<Boolean> STILL_HOSTILE = SynchedEntityData.defineId(TyBoss.class, EntityDataSerializers.BOOLEAN); private static final EntityDataAccessor<Byte> SCOUNT_TAG = SynchedEntityData.defineId(TyBoss.class, EntityDataSerializers.BYTE); (...) protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(SCOUNT_TAG, (byte) 0); this.entityData.define(STILL_HOSTILE, true); } (...) public void startSeenByPlayer(ServerPlayer p_01_) { super.startSeenByPlayer(p_01_); if (this.entityData.get(STILL_HOSTILE)) { this.bossEvent.addPlayer(p_01_);} } public void stopSeenByPlayer(ServerPlayer p_01_) { super.stopSeenByPlayer(p_01_); this.bossEvent.removePlayer(p_01_); } (...) }  
    • Error downloading These libraries failed to download. Try again. org.scala-lang.plugins.scala-continuations-library_2.11:1.0.2 org.scala-lang.plugins.scala-continuations-plugin_2.11.1:1.0.2  
    • file:///C:/Users/chinc/Downloads/forge-1.17.1-37.0.103-installer.jar.log
    • ---- Minecraft Crash Report ---- // Who set us up the TNT? Time: 10/24/21, 8:51 PM Description: Initializing game org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered     at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363)     at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:208)     at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClassBytes(MixinTransformer.java:178)     at org.spongepowered.asm.mixin.transformer.FabricMixinTransformerProxy.transformClassBytes(FabricMixinTransformerProxy.java:23)     at meteordevelopment.meteorclient.MixinPlugin$Transformer.transformClassBytes(MixinPlugin.java:37)     at net.fabricmc.loader.launch.knot.KnotClassDelegate.getPostMixinClassByteArray(KnotClassDelegate.java:162)     at net.fabricmc.loader.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:154)     at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)     at net.minecraft.class_757.<init>(class_757.java:283)     at net.minecraft.class_310.<init>(class_310.java:565)     at net.minecraft.client.main.Main.main(Main.java:179)     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.base/java.lang.reflect.Method.invoke(Method.java:567)     at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:234)     at net.fabricmc.loader.launch.knot.Knot.launch(Knot.java:153)     at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:28) Caused by: org.spongepowered.asm.mixin.injection.throwables.InjectionError: Critical injection failure: Redirector updateHasStatusEffectProxy(Lnet/minecraft/class_746;Lnet/minecraft/class_1291;)Z in meteor-client.mixins.json:LightmapTextureManagerMixin failed injection check, (0/1) succeeded. Scanned 1 target(s). Using refmap meteor-client-refmap.json     at org.spongepowered.asm.mixin.injection.struct.InjectionInfo.postInject(InjectionInfo.java:408)     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.applyInjections(MixinTargetContext.java:1291)     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyInjections(MixinApplicatorStandard.java:1042)     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyMixin(MixinApplicatorStandard.java:395)     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:320)     at org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:345)     at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:569)     at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:351)     ... 17 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363)     at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:208)     at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClassBytes(MixinTransformer.java:178)     at org.spongepowered.asm.mixin.transformer.FabricMixinTransformerProxy.transformClassBytes(FabricMixinTransformerProxy.java:23)     at meteordevelopment.meteorclient.MixinPlugin$Transformer.transformClassBytes(MixinPlugin.java:37)     at net.fabricmc.loader.launch.knot.KnotClassDelegate.getPostMixinClassByteArray(KnotClassDelegate.java:162)     at net.fabricmc.loader.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:154)     at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)     at net.minecraft.class_757.<init>(class_757.java:283)     at net.minecraft.class_310.<init>(class_310.java:565) -- Initialization -- Details: Stacktrace:     at net.minecraft.client.main.Main.main(Main.java:179)     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.base/java.lang.reflect.Method.invoke(Method.java:567)     at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:234)     at net.fabricmc.loader.launch.knot.Knot.launch(Knot.java:153)     at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:28) -- System Details -- Details:     Minecraft Version: 1.17.1     Minecraft Version ID: 1.17.1     Operating System: Windows 10 (amd64) version 10.0     Java Version: 16.0.1, Microsoft     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Microsoft     Memory: 653549032 bytes (623 MiB) / 1778384896 bytes (1696 MiB) up to 2147483648 bytes (2048 MiB)     CPUs: 12     Processor Vendor: AuthenticAMD     Processor Name: AMD Ryzen 5 3600 6-Core Processor                   Identifier: AuthenticAMD Family 23 Model 113 Stepping 0     Microarchitecture: Zen 2     Frequency (GHz): 3.59     Number of physical packages: 1     Number of physical CPUs: 6     Number of logical CPUs: 12     Graphics card #0 name: Radeon RX 580 Series     Graphics card #0 vendor: Advanced Micro Devices, Inc. (0x1002)     Graphics card #0 VRAM (MB): 4095.00     Graphics card #0 deviceId: 0x67df     Graphics card #0 versionInfo: DriverVersion=27.20.22025.1006     Memory slot #0 capacity (MB): 8192.00     Memory slot #0 clockSpeed (GHz): 2.40     Memory slot #0 type: DDR4     Virtual memory max (MB): 30651.30     Virtual memory used (MB): 17073.36     Swap memory total (MB): 22528.00     Swap memory used (MB): 1513.81     JVM Flags: 9 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xss1M -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     Fabric Mods:          apoli: Apoli 2.0.3         baritone: Baritone 1.7.0         calio: Calio 1.0.3         cardinal-components-base: Cardinal Components API (base) 3.1.1         cardinal-components-entity: Cardinal Components API (entities) 3.1.1         cloth-basic-math: Cloth Basic Math 0.5.1         cloth-config2: Cloth Config v4 5.0.34         fabric: Fabric API 0.41.0+1.17         fabric-api-base: Fabric API Base 0.3.0+a02b446318         fabric-api-lookup-api-v1: Fabric API Lookup API (v1) 1.3.0+cbda931818         fabric-biome-api-v1: Fabric Biome API (v1) 3.2.0+cbda931818         fabric-blockrenderlayer-v1: Fabric BlockRenderLayer Registration (v1) 1.1.5+a02b446318         fabric-command-api-v1: Fabric Command API (v1) 1.1.3+5ab9934c18         fabric-commands-v0: Fabric Commands (v0) 0.2.2+92519afa18         fabric-containers-v0: Fabric Containers (v0) 0.1.12+cbda931818         fabric-content-registries-v0: Fabric Content Registries (v0) 0.3.0+cbda931818         fabric-crash-report-info-v1: Fabric Crash Report Info (v1) 0.1.5+be9da31018         fabric-dimensions-v1: Fabric Dimensions API (v1) 2.0.11+6cefd57718         fabric-entity-events-v1: Fabric Entity Events (v1) 1.3.0+57bef5a318         fabric-events-interaction-v0: Fabric Events Interaction (v0) 0.4.10+fc40aa9d18         fabric-events-lifecycle-v0: Fabric Events Lifecycle (v0) 0.2.1+92519afa18         fabric-game-rule-api-v1: Fabric Game Rule API (v1) 1.0.7+cbda931818         fabric-item-api-v1: Fabric Item API (v1) 1.2.4+cbda931818         fabric-item-groups-v0: Fabric Item Groups (v0) 0.2.10+b7ab612118         fabric-key-binding-api-v1: Fabric Key Binding API (v1) 1.0.4+cbda931818         fabric-keybindings-v0: Fabric Key Bindings (v0) 0.2.2+36b77c3e18         fabric-lifecycle-events-v1: Fabric Lifecycle Events (v1) 1.4.4+a02b446318         fabric-loot-tables-v1: Fabric Loot Tables (v1) 1.0.4+a02b446318         fabric-mining-levels-v0: Fabric Mining Levels (v0) 0.1.3+92519afa18         fabric-models-v0: Fabric Models (v0) 0.3.0+a02b446318         fabric-networking-api-v1: Fabric Networking API (v1) 1.0.13+cbda931818         fabric-networking-blockentity-v0: Fabric Networking Block Entity (v0) 0.2.11+a02b446318         fabric-networking-v0: Fabric Networking (v0) 0.3.2+92519afa18         fabric-object-builder-api-v1: Fabric Object Builder API (v1) 1.10.9+cbda931818         fabric-object-builders-v0: Fabric Object Builders (v0) 0.7.3+a02b446318         fabric-particles-v1: Fabric Particles (v1) 0.2.4+a02b446318         fabric-registry-sync-v0: Fabric Registry Sync (v0) 0.7.11+7931163218         fabric-renderer-api-v1: Fabric Renderer API (v1) 0.4.4+cbda931818         fabric-renderer-indigo: Fabric Renderer - Indigo 0.4.8+cbda931818         fabric-renderer-registries-v1: Fabric Renderer Registries (v1) 3.2.4+7931163218         fabric-rendering-data-attachment-v1: Fabric Rendering Data Attachment (v1) 0.1.5+a02b446318         fabric-rendering-fluids-v1: Fabric Rendering Fluids (v1) 0.1.14+4658223018         fabric-rendering-v0: Fabric Rendering (v0) 1.1.5+7931163218         fabric-rendering-v1: Fabric Rendering (v1) 1.9.0+7931163218         fabric-resource-loader-v0: Fabric Resource Loader (v0) 0.4.8+a00e834b18         fabric-screen-api-v1: Fabric Screen API (v1) 1.0.4+cbda931818         fabric-screen-handler-api-v1: Fabric Screen Handler API (v1) 1.1.8+cbda931818         fabric-structure-api-v1: Fabric Structure API (v1) 1.1.13+5ab9934c18         fabric-tag-extensions-v0: Fabric Tag Extensions (v0) 1.2.1+b06cb95b18         fabric-textures-v0: Fabric Textures (v0) 1.0.6+a02b446318         fabric-tool-attribute-api-v1: Fabric Tool Attribute API (v1) 1.2.12+b7ab612118         fabric-transfer-api-v1: Fabric Transfer API (v1) 1.4.0+7931163218         fabricloader: Fabric Loader 0.11.7         fallflyinglib: FallFlyingLib 3.0.0-beta.2         java: OpenJDK 64-Bit Server VM 16         meteor-client: Meteor Client 0.4.5         minecraft: Minecraft 1.17.1         origins: Origins 1.1.2         playerabilitylib: Pal 1.3.0-nightly.1.17-rc1         reach-entity-attributes: Reach Entity Attributes 2.1.1     Launched Version: fabric-loader-0.11.7-1.17.1     Backend library: LWJGL version 3.2.2 build 10     Backend API: Radeon RX 580 Series GL version 3.2.14742 Core Profile Forward-Compatible Context 21.8.2 27.20.22025.1006, ATI Technologies Inc.     Window size: <not initialized>     GL Caps: Using framebuffer using OpenGL 3.2     GL debug messages:      Using VBOs: Yes     Is Modded: Definitely; Client brand changed to 'fabric'     Type: Client (map_client.txt)     CPU: 12x AMD Ryzen 5 3600 6-Core Processor 
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.