Jump to content

Recommended Posts

Posted

Hello,

 

I've recently started modding again so I'm still fairly new to the 1.13 changes.

As capabilities have changed somewhat, I'm getting stuck trying to read/write the cap data when the player first joins: I get a NullPointer when I first login after the capability gets attached. Meaning, the first login works, but any following attempts fail will crash:

net.minecraft.crash.ReportedException: Loading entity NBT
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:154) ~[?:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:882) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:800) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646) [?:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_231] {}
Caused by: java.lang.NullPointerException
	at net.minecraftforge.fml.network.PacketDistributor.lambda$playerConsumer$1(PacketDistributor.java:216) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.network.PacketDistributor$PacketTarget.send(PacketDistributor.java:178) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.network.simple.SimpleChannel.send(SimpleChannel.java:118) ~[?:?] {re:classloading}
	at com.unassigned.voidmagic.common.capability.playervoid.impl.PlayerVoid.setVoidStored(PlayerVoid.java:61) ~[?:?] {re:classloading}
	at com.unassigned.voidmagic.common.capability.playervoid.PlayerVoidStorage.readNBT(PlayerVoidStorage.java:37) ~[?:?] {re:classloading}
	at com.unassigned.voidmagic.common.capability.playervoid.PlayerVoidStorage.readNBT(PlayerVoidStorage.java:10) ~[?:?] {re:classloading}
	at com.unassigned.voidmagic.common.capability.playervoid.PlayerVoidProvider.deserializeNBT(PlayerVoidProvider.java:39) ~[?:?] {re:classloading,pl:capability_inject_definalize:A}
	at com.unassigned.voidmagic.common.capability.playervoid.PlayerVoidProvider.deserializeNBT(PlayerVoidProvider.java:15) ~[?:?] {re:classloading,pl:capability_inject_definalize:A}
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.deserializeNBT(CapabilityDispatcher.java:139) ~[?:?] {re:classloading}
	at net.minecraftforge.common.capabilities.CapabilityProvider.deserializeCaps(CapabilityProvider.java:96) ~[?:?] {re:classloading}
	at net.minecraft.entity.Entity.read(Entity.java:1656) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.management.PlayerList.readPlayerDataFromFile(PlayerList.java:269) ~[?:?] {re:classloading}
	at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:112) ~[?:?] {re:classloading}
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:119) ~[?:?] {re:classloading}
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:63) ~[?:?] {re:classloading}
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:241) ~[?:?] {re:classloading}
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:148) ~[?:?] {re:classloading}
	... 5 more

 

I should also add that it does not crash when I send the packet through other means. I do have some idea to what is causing this crash, however: the packet to update the server w/ the client is being sent while the client is not actually connected yet. I found this result through checking if the client is connected before syncing the data, however this leads to the values not being synced once the NBT is set. I just have no idea on how to fix this problem.

 

Here is the code that is within the stacktrace, and here is my github if you need to see anything else.

 

PlayerVoidStorage (Capability Storage Class):

  Reveal hidden contents

 

PlayerVoidProvider (Capability Provider Class):

  Reveal hidden contents

 

PlayerVoid (impl of IPlayerVoid):

  Reveal hidden contents

 

Posted

You should have a reference to your actual capability and only use/provide your LazyOptional for external operations.

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 1/7/2020 at 2:21 AM, Cadiboo said:

You should have a reference to your actual capability and only use/provide your LazyOptional for external operations.

Expand  

Yeah, I just needed some clarification on the new LazyOptional system, as I'm still not too sure what/when to use them. So doing something like this:

                e.getCapability(PlayerVoidProvider.CAPABILITY_PLAYER_VOID).ifPresent(pv -> pv.setVoidStored(message.playerVoid));

isn't correct? Or am I mistaking what you are meaning.

 

Posted

If you know that the object exists and have access to it, you shouldn’t be using an optional. An Optional should be exposed to the rest of the world with getCapability BUT you know that your capability will never be null so you should use a direct reference in your internal code.

About Me

  Reveal hidden contents

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
  On 1/7/2020 at 5:16 AM, Cadiboo said:

If you know that the object exists and have access to it, you shouldn’t be using an optional. An Optional should be exposed to the rest of the world with getCapability BUT you know that your capability will never be null so you should use a direct reference in your internal code.

Expand  

Ok. I think I see what you are meaning, however I still don't exactly see where I'm doing anything wrong. I know when I get the capability to send the packet that the cap isn't ever null, so direct reference is fine in this case I believe.

Posted

I believe I went through and changed what needed to be changed, but I still get the same error. I did quite the rewrite to get everything in order again, and just for optimization purposes. Here is the stacktrace again:

  Reveal hidden contents

 

Here are some direct links to the proper github files, as those will house the lines where everything is happening.

CapabilityPlayerVoid

PlayerVoid

MessagePlayerVoid

 

Thank you both for your help so far.

Posted
  On 1/8/2020 at 9:17 AM, diesieben07 said:

You are trying to send a packet while being read from NBT. That does not work, the player doesn't exist fully yet, so you can't send a packet to it.

Expand  

Ah gotcha. I did the following, which is quite hacky but seems to work: I added a parameter to the setVoidStored to send the packet or not, then send the packet when the entity joins the world.

 

new readNBT within the cap:

                            instance.setVoidStored(compound.getInt("VoidStored"), false);

 

new event to send the packet after the player is done connecting:

    @SubscribeEvent
    public void onJoinWorld(EntityJoinWorldEvent event) {
        Entity e = event.getEntity();
        if(e != null) {
            if(e instanceof PlayerEntity) {
                CapabilityPlayerVoid.getPlayerVoid((PlayerEntity)e).ifPresent(IPlayerVoid::onVoidChanged);
            }
        }
    }

 

Let me know if there is a simpler way of doing it. Other than that thanks for your help!

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



×
×
  • Create New...

Important Information

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