Jump to content

Capability synchronization


FeedokTV

Recommended Posts

Sup! I'm so sorry for asking questuions so often.
Now Im stydying how to work with capabilities and netwrok. I have a cap which contains some int id. It changes in custom menu. I want to synchronize it with other players, but so far it hasn't worked. Could someone who knows me give me an idea or tell me how to implement it.

 

public class UpdateCapPacket extends AbstractMessage<UpdateCapPacket> {

    private int hatId;

    public UpdateCapPacket() {

    }

    public UpdateCapPacket(int id) {
        this.hatId = id;
    }

    @Override
    public void encode(UpdateCapPacket message, PacketBuffer buffer) {
        buffer.writeInt(message.hatId);
    }

    @Override
    public UpdateCapPacket decode(PacketBuffer buffer) {
        int id = buffer.readInt();
        return new UpdateCapPacket(hatId);
    }

    @Override
    public void handle(UpdateCapPacket message, Supplier<NetworkEvent.Context> ctx) {
        if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT)
            ctx.get().enqueueWork(() ->
            {
                InfCust.LOGGER.error("[UPDATING CAP PACKET]");
                final Optional<World> optionalWorld = LogicalSidedProvider.CLIENTWORLD.get(ctx.get().getDirection().getReceptionSide());
                final LivingEntity livingEntity = ctx.get().getSender();
                if (livingEntity != null) {
                  // Living entity is always null, whats wrong 
                    InfCust.LOGGER.error("[CHANGING CAP]");
                    optionalWorld.ifPresent(world -> InfCust.capabilityUtil.updateCapabilityHatId(message.hatId));
                }
                InfCust.LOGGER.error(InfCust.capabilityUtil.getCapabilityHatId());
            });
        ctx.get().setPacketHandled(true);
    }
}


public void OpenCustMenu() {
        // For example
        Minecraft.getInstance().setScreen(new CustomizationScreen());
        PacketDispatcher.sendToAll(new UpdateCapPacket(-1));
    }

 

Link to comment
Share on other sites

4 hours ago, diesieben07 said:

This makes zero sense in a server side packet.

What is this? You must obtain the capability from the player, you can't just put it in a static field somewhere.


CapabilityUtil

 

public void updateCapabilityHatId(int id)
    {
        ClientPlayerEntity player = Minecraft.getInstance().player;
        player.getCapability(HatCapability.PLAYER_HAT_ID).ifPresent((Data) -> Data.setValue(id));
    }

    public int getCapabilityHatId()
    {
        ClientPlayerEntity player = Minecraft.getInstance().player;
        if (player != null) {
            int id = player.getCapability(HatCapability.PLAYER_HAT_ID)
                    .map(capa -> capa.getValue())
                    .orElse(0);
            return id;
        }
        else return -1;

    }

Something like a helper to me.

So how can I make this packet correctly. Sorry for the question, I'm just starting to understand this whole topic and don't understand how exactly to make this packet

Link to comment
Share on other sites

Huh, understand. I think I can get by ctx.get().getSender().getId();
But, how correctly I have to work with this id? If it's not difficult for you, could you show or tell how exactly I should contact the player by his id in my packet?

Link to comment
Share on other sites

So, im trying to make updating system with id, first of all I wanted to see this id, but

This is my handle code and error message

@Override
    public void handle(UpdateCapPacket message, Supplier<NetworkEvent.Context> ctx) {
        if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
            ctx.get().enqueueWork(() ->
            {
                InfCust.LOGGER.error("[UPDATING CAP PACKET]");
                InfCust.LOGGER.error(ctx.get().getSender().getId());
            });
            ctx.get().setPacketHandled(true);
        }
    }
[23:12:09] [Render thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client
java.lang.NullPointerException: null
	at net.minecraftforge.fml.LogicalSidedProvider.lambda$static$3(LogicalSidedProvider.java:33) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.LogicalSidedProvider.get(LogicalSidedProvider.java:60) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.PacketDistributor.getServer(PacketDistributor.java:264) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.PacketDistributor.lambda$playerListAll$3(PacketDistributor.java:224) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.PacketDistributor$PacketTarget.send(PacketDistributor.java:179) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.SimpleChannel.send(SimpleChannel.java:124) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at com.feedoktv.infcust.common.core.networking.PacketDispatcher.sendToAll(PacketDispatcher.java:66) ~[main/:?] {re:classloading}
	at com.feedoktv.infcust.client.handlers.EventHandlerClient.OpenCustMenu(EventHandlerClient.java:82) ~[main/:?] {re:classloading}
	at com.feedoktv.infcust.common.core.networking.packets.OpenMainMenuPacket.lambda$handle$0(OpenMainMenuPacket.java:26) ~[main/:?] {re:classloading}
	at net.minecraftforge.fml.network.NetworkEvent$Context.enqueueWork(NetworkEvent.java:215) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at com.feedoktv.infcust.common.core.networking.packets.OpenMainMenuPacket.handle(OpenMainMenuPacket.java:23) ~[main/:?] {re:classloading}
	at com.feedoktv.infcust.common.core.networking.packets.OpenMainMenuPacket.handle(OpenMainMenuPacket.java:10) ~[main/:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.IndexedMessageCodec.lambda$tryDecode$3(IndexedMessageCodec.java:128) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_311] {}
	at net.minecraftforge.fml.network.simple.IndexedMessageCodec.tryDecode(IndexedMessageCodec.java:128) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.IndexedMessageCodec.consume(IndexedMessageCodec.java:162) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.SimpleChannel.networkEventListener(SimpleChannel.java:80) ~[forge-1.16.5-36.2.29_mapped_official_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.29_mapped_official_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.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_311] {}
	at net.minecraftforge.fml.network.NetworkHooks.onCustomPayload(NetworkHooks.java:91) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.client.network.play.ClientPlayNetHandler.handleCustomPayload(ClientPlayNetHandler.java:1904) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.network.play.server.SCustomPayloadPlayPacket.handle(SCustomPayloadPlayPacket.java:59) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.network.play.server.SCustomPayloadPlayPacket.handle(SCustomPayloadPlayPacket.java:11) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.network.PacketThreadUtil.lambda$ensureRunningOnSameThread$0(PacketThreadUtil.java:19) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.doRunTask(ThreadTaskExecutor.java:136) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.RecursiveEventLoop.doRunTask(RecursiveEventLoop.java:22) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.pollTask(ThreadTaskExecutor.java:109) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.runAllTasks(ThreadTaskExecutor.java:97) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:948) ~[forge-1.16.5-36.2.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:607) ~[forge-1.16.5-36.2.29_mapped_official_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.29_mapped_official_1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_311] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_311] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_311] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_311] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.29_mapped_official_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.29_mapped_official_1.16.5-recomp.jar:?] {}

 

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

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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