Luis_ST Posted May 31, 2022 Share Posted May 31, 2022 51 minutes ago, auriny said: like this? this will send the packet to all players, but yeah this should work Quote Link to comment Share on other sites More sharing options...
auriny Posted May 31, 2022 Author Share Posted May 31, 2022 1 minute ago, Luis_ST said: this will send the packet to all players, but yeah this should work Quote [01:08:36] [Render thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client java.lang.NullPointerException: null at com.auriny.cosrpg.capability.PacketEtherBar.lambda$handle$0(PacketEtherBar.java:39) ~[main/:?] {re:classloading} at net.minecraftforge.fml.network.NetworkEvent$Context.enqueueWork(NetworkEvent.java:215) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at com.auriny.cosrpg.capability.PacketEtherBar.handle(PacketEtherBar.java:38) ~[main/:?] {re:classloading} at net.minecraftforge.fml.network.simple.IndexedMessageCodec.lambda$tryDecode$3(IndexedMessageCodec.java:128) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_181] {} at net.minecraftforge.fml.network.simple.IndexedMessageCodec.tryDecode(IndexedMessageCodec.java:128) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraftforge.fml.network.simple.IndexedMessageCodec.consume(IndexedMessageCodec.java:162) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraftforge.fml.network.simple.SimpleChannel.networkEventListener(SimpleChannel.java:80) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {} at net.minecraftforge.fml.network.NetworkInstance.dispatch(NetworkInstance.java:86) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraftforge.fml.network.NetworkHooks.lambda$onCustomPayload$1(NetworkHooks.java:91) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_181] {} at net.minecraftforge.fml.network.NetworkHooks.onCustomPayload(NetworkHooks.java:91) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraft.client.network.play.ClientPlayNetHandler.handleCustomPayload(ClientPlayNetHandler.java:2054) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.network.play.server.SCustomPayloadPlayPacket.processPacket(SCustomPayloadPlayPacket.java:68) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraft.network.play.server.SCustomPayloadPlayPacket.processPacket(SCustomPayloadPlayPacket.java:11) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:139) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading} at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:109) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:97) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:974) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.client.Minecraft.run(Minecraft.java:612) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A} at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181] {} at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_181] {} at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_181] {} at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_181] {} at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?] {} at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?] {} at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?] {} at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?] {} at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {} npe public class PacketEtherBar { private int delay; private float ether; private float max; public PacketEtherBar(ByteBuf buf) { max = buf.readFloat(); ether = buf.readFloat(); delay = buf.readInt(); } public void toBytes(ByteBuf buf) { buf.writeFloat(max); buf.writeFloat(ether); buf.writeInt(delay); } public PacketEtherBar(Ether ether) { if (ether == null) return; delay = ether.getRegenDelay(); this.ether = ether.getEther(); max = ether.getMaxEther(); } public void handle(Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { Ether ether = Objects.requireNonNull(ctx.get().getSender()).getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.setMaxEther(max); ether.setRegenDelay(delay); ether.set(this.ether); }); ctx.get().setPacketHandled(true); } @SubscribeEvent public void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) { Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.fill(event.getPlayer(), ether.getEther()); } @SubscribeEvent public void onChangeDimension(PlayerEvent.PlayerChangedDimensionEvent event) { Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.fill(event.getPlayer(), ether.getMaxEther()-ether.getEther()); } @SubscribeEvent public void onLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.fill(event.getPlayer(), ether.getEther()); } } Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted May 31, 2022 Share Posted May 31, 2022 2 minutes ago, auriny said: Objects.requireNonNull(ctx.get().getSender()) there is no sender on the client, due you sync your capability to all players you have to send the associated player's network id to the client then you can get the Player on client side via ClientWorld#getEntityByID you also need to note that Packets whach are sent from the server to the client should be handled in another class and wrapped via DistExecutor#unsafeRunWhenOn you can take a look at this as an example (the second code part) Quote Link to comment Share on other sites More sharing options...
auriny Posted May 31, 2022 Author Share Posted May 31, 2022 8 minutes ago, Luis_ST said: ClientWorld#getEntityByID mmh how to use it? sorry im so stupid Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted May 31, 2022 Share Posted May 31, 2022 it's a method you should call it you can get the ClientWorld from: Minecraft.getInstance().world Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 (edited) 10 hours ago, Luis_ST said: it's a method you should call it you can get the ClientWorld from: Minecraft.getInstance().world ok, im trying Edited June 1, 2022 by auriny Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 11 hours ago, Luis_ST said: it's a method you should call it you can get the ClientWorld from: Minecraft.getInstance().world i can't, i just don’t understand where to put it Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 34 minutes ago, diesieben07 said: You should only send the packet to the player actually owning the capability. There is no reason to distribute it to all nearby ("tracking") players, let alone all players. but all of the players owning this capability Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 38 minutes ago, diesieben07 said: You should only send the packet to the player actually owning the capability. and how to send this packet only for players that owning that cap? Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 1 minute ago, diesieben07 said: PacketDistributor.PLAYER noArg? Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 (edited) oh Edited June 1, 2022 by auriny Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 (edited) 5 minutes ago, diesieben07 said: PacketTarget.PLAYER.with(() -> your player here) sorry, but i'm still don't understand how to get player that owning my capability Edited June 1, 2022 by auriny Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 2 hours ago, diesieben07 said: Pass it as a constructor parameter to your capability instance. how.... Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted June 1, 2022 Share Posted June 1, 2022 if you don't know how to pass in a parameter to the constructor and storing this parameter in a final field you should learn basic java first Quote Link to comment Share on other sites More sharing options...
auriny Posted June 1, 2022 Author Share Posted June 1, 2022 2 hours ago, Luis_ST said: if you don't know how to pass in a parameter to the constructor and storing this parameter in a final field you should learn basic java first the problem is that im russian, and most likely it sounds different in my language, so i don't understand what you are talking about. sorry i will try google now, ofc Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.