Jump to content

Recommended Posts

Posted

Okay, so I'm having some trouble here.

I want to, under a certain condition, have the player's inventory (either the entire thing, or only certain items, depending on the condition) to be kept after death.

Currently, I am just saving an InventoryPlayer variable which I store items in on LivingDeathEvent, and restore on PlayerEvent.Clone. There is an issue I have found, however- if the player disconnects from the server before clicking "Respawn", the inventory is completely lost- not just not kept through death, but does not drop either.

What I have figured out is that I need to save the backup of the inventory to the player.

Everything I can find online through searching tells me I should be using "IExtendedEntityProperties", though in 1.12 that doesn't appear to exist? How would I go about this in 1.12?

(forge version is 14.23.4.2709 btw)

Posted

I've now spent an hour looking over capabilities and getting it to work, but I still have an issue.

Code:  https://github.com/venrob/RobsStuff-mcmod/tree/add-capabilities/main/java/com/venrob/robsstuff

The relevant code is at /capabilities, as well as /utils/handlers/CapabilityHandler.java and /utils/handlers/EventHandler.java

When the player dies, it should store the inventory in the capability, but the call to

CapabilityHandler.getCapabilityInv(Entity entity)

returns false. Should the entityPlayer not have the capability from the @SubscribeEvent method

attachCapabilityEntity(AttachCapabilitiesEvent<Entity> event)

?

What am I missing here?

Posted (edited)

Oh... I forgot about the static thing AGAIN. Testing that now...

The InventoryPlayer that is being passed is already a copy of the original, so it should work fine. (EventHandler.java , InventoryPlayer newInv = new InventoryPlayer(player))

Edited by Venrob
Posted (edited)

Well something is dreadfully wrong now... it crashed the instant I loaded a save.

Spoiler

[net.minecraft.init.Bootstrap:func_179870_a:553]: ---- Minecraft Crash Report ---- // Daisy, daisy... Time: 7/4/18 9:46 AM Description: Saving entity NBT java.lang.NullPointerException: Saving entity NBT at com.venrob.robsstuff.capabilities.IInventoryBackupStorage.writeNBT(IInventoryBackupStorage.java:21) at com.venrob.robsstuff.capabilities.IInventoryBackupStorage.writeNBT(IInventoryBackupStorage.java:14) at com.venrob.robsstuff.capabilities.IInventoryBackupProvider.serializeNBT(IInventoryBackupProvider.java:29) at com.venrob.robsstuff.capabilities.IInventoryBackupProvider.serializeNBT(IInventoryBackupProvider.java:12) at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:123) at net.minecraft.entity.Entity.func_189511_e(Entity.java:1738) at net.minecraft.server.integrated.IntegratedPlayerList.func_72391_b(SourceFile:22) at net.minecraft.server.management.PlayerList.func_72389_g(PlayerList.java:942) at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:169) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524) at java.lang.Thread.run(Thread.java:745) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace: at com.venrob.robsstuff.capabilities.IInventoryBackupStorage.writeNBT(IInventoryBackupStorage.java:21) at com.venrob.robsstuff.capabilities.IInventoryBackupStorage.writeNBT(IInventoryBackupStorage.java:14) at com.venrob.robsstuff.capabilities.IInventoryBackupProvider.serializeNBT(IInventoryBackupProvider.java:29) at com.venrob.robsstuff.capabilities.IInventoryBackupProvider.serializeNBT(IInventoryBackupProvider.java:12) at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:123) -- Entity being saved -- Details: Entity Type: null (net.minecraft.entity.player.EntityPlayerMP) Entity ID: 174 Entity Name: SuperGamerRob Entity's Exact location: 225.25, 65.16, 62.29 Entity's Block location: World: (225,65,62), Chunk: (at 1,4,14 in 14,3; contains blocks 224,0,48 to 239,255,63), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Entity's Momentum: -0.01, -0.23, -0.00 Entity's Passengers: [] Entity's Vehicle: ~~ERROR~~ NullPointerException: null Stacktrace: at net.minecraft.entity.Entity.func_189511_e(Entity.java:1738) at net.minecraft.server.integrated.IntegratedPlayerList.func_72391_b(SourceFile:22) at net.minecraft.server.management.PlayerList.func_72389_g(PlayerList.java:942) at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:169) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524) at java.lang.Thread.run(Thread.java:745) -- System Details -- Details: Minecraft Version: 1.12.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_51, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 1046071160 bytes (997 MB) / 1296564224 bytes (1236 MB) up to 5726797824 bytes (5461 MB) JVM Flags: 4 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx6144m -Xms256m -XX:PermSize=256m IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94 FML: MCP 9.42 Powered by Forge 14.23.3.2691 6 mods loaded, 6 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored | State | ID | Version | Source | Signature | |:--------- |:--------- |:------------ |:----------------------------- |:---------------------------------------- | | UCHIJAAAA | minecraft | 1.12.2 | minecraft.jar | None | | UCHIJAAAA | mcp | 9.42 | minecraft.jar | None | | UCHIJAAAA | FML | 8.0.99.99 | forge-1.12.2-14.23.3.2691.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 | | UCHIJAAAA | forge | 14.23.3.2691 | forge-1.12.2-14.23.3.2691.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 | | UCHIJAAAA | robsstuff | 1.0.2 | RobsStuff-1.2.jar | None | | UCHIJAAAA | rum | 1.1 | RobUtils-1.3.jar | None | Loaded coremods (and transformers): GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Player Count: 1 / 8; [EntityPlayerMP['SuperGamerRob'/174, l='New World', x=225.25, y=65.16, z=62.29]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'

...So from what I gather, it gets a NullPo when it checks if I am riding something? What is causing THAT?

(I haven't updated the repo, but literally the only change made was changing the @SubscribeEvent to being static)

Also, the error line is line 21 of the Storage class... that is the first line of a for loop... the only method called is inv.mainInventory.size(), which shouldn't be able to cause THIS.

Edited by Venrob
Posted
Spoiler

---- Minecraft Crash Report ----
// Quite honestly, I wouldn't worry myself about that.

Time: 7/4/18 9:46 AM
Description: Saving entity NBT

java.lang.NullPointerException: Saving entity NBT
    at com.venrob.robsstuff.capabilities.IInventoryBackupStorage.writeNBT(IInventoryBackupStorage.java:21)
    at com.venrob.robsstuff.capabilities.IInventoryBackupStorage.writeNBT(IInventoryBackupStorage.java:14)
    at com.venrob.robsstuff.capabilities.IInventoryBackupProvider.serializeNBT(IInventoryBackupProvider.java:29)
    at com.venrob.robsstuff.capabilities.IInventoryBackupProvider.serializeNBT(IInventoryBackupProvider.java:12)
    at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:123)
    at net.minecraft.entity.Entity.func_189511_e(Entity.java:1738)
    at net.minecraft.server.integrated.IntegratedPlayerList.func_72391_b(SourceFile:22)
    at net.minecraft.server.management.PlayerList.func_72389_g(PlayerList.java:942)
    at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:169)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524)
    at java.lang.Thread.run(Thread.java:745)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
    at com.venrob.robsstuff.capabilities.IInventoryBackupStorage.writeNBT(IInventoryBackupStorage.java:21)
    at com.venrob.robsstuff.capabilities.IInventoryBackupStorage.writeNBT(IInventoryBackupStorage.java:14)
    at com.venrob.robsstuff.capabilities.IInventoryBackupProvider.serializeNBT(IInventoryBackupProvider.java:29)
    at com.venrob.robsstuff.capabilities.IInventoryBackupProvider.serializeNBT(IInventoryBackupProvider.java:12)
    at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:123)

-- Entity being saved --
Details:
    Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
    Entity ID: 174
    Entity Name: SuperGamerRob
    Entity's Exact location: 225.25, 65.16, 62.29
    Entity's Block location: World: (225,65,62), Chunk: (at 1,4,14 in 14,3; contains blocks 224,0,48 to 239,255,63), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Entity's Momentum: -0.01, -0.23, -0.00
    Entity's Passengers: []
    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.entity.Entity.func_189511_e(Entity.java:1738)
    at net.minecraft.server.integrated.IntegratedPlayerList.func_72391_b(SourceFile:22)
    at net.minecraft.server.management.PlayerList.func_72389_g(PlayerList.java:942)
    at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:169)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524)
    at java.lang.Thread.run(Thread.java:745)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_51, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 1046071160 bytes (997 MB) / 1296564224 bytes (1236 MB) up to 5726797824 bytes (5461 MB)
    JVM Flags: 4 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx6144m -Xms256m -XX:PermSize=256m
    IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
    FML: MCP 9.42 Powered by Forge 14.23.3.2691 6 mods loaded, 6 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State     | ID        | Version      | Source                        | Signature                                |
    |:--------- |:--------- |:------------ |:----------------------------- |:---------------------------------------- |
    | UCHIJAAAA | minecraft | 1.12.2       | minecraft.jar                 | None                                     |
    | UCHIJAAAA | mcp       | 9.42         | minecraft.jar                 | None                                     |
    | UCHIJAAAA | FML       | 8.0.99.99    | forge-1.12.2-14.23.3.2691.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 |
    | UCHIJAAAA | forge     | 14.23.3.2691 | forge-1.12.2-14.23.3.2691.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 |
    | UCHIJAAAA | robsstuff | 1.0.2        | RobsStuff-1.2.jar             | None                                     |
    | UCHIJAAAA | rum       | 1.1          | RobUtils-1.3.jar              | None                                     |

    Loaded coremods (and transformers): 
    GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
    Profiler Position: N/A (disabled)
    Player Count: 1 / 8; [EntityPlayerMP['SuperGamerRob'/174, l='New World', x=225.25, y=65.16, z=62.29]]
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'fml,forge'

I don't know what to tell you, I opened the crash report and copy/pasted. Here's a version with fixed spacing/newlines

Posted

Okay, that's fixed, but now there's a new crash. This one I know exactly the problem at least, but no clue how to fix it.

Provider#serializeNBT returns NBTTagCompound, but the inventory is saved as an NBTTagList. How would I go about converting/changing this?

Posted

Right, okay. (Followed tutorial to a T, didn't realize that was a thing I had specified).

Now when I die with the keeping medallion in my inventory, the entire inventory is just deleted. (I'm going to go through and set up some debug logging to see exactly where it is failing)

 

Posted

Okay, there were several more issues, but I seem to have it working perfectly now! For some reason, despite the InventoryPlayer being passed being just a copy of the original, it was still being cleared when the original was cleared. Don't know why, don't care anymore- I changed it so that the capability simply stores the items in 3 ItemStack[]'s (returning them in an ItemStack[][]).

 

Best part? When dying, then returning to Title Screen before respawning, then rejoining and respawning, THE INVENTORY STILL LOADS SUCCESSFULLY! Thank you so much for your help!

Posted
On 7/5/2018 at 2:32 AM, Venrob said:

Okay, there were several more issues, but I seem to have it working perfectly now! For some reason, despite the InventoryPlayer being passed being just a copy of the original, it was still being cleared when the original was cleared. Don't know why, don't care anymore- I changed it so that the capability simply stores the items in 3 ItemStack[]'s (returning them in an ItemStack[][]).

 

Best part? When dying, then returning to Title Screen before respawning, then rejoining and respawning, THE INVENTORY STILL LOADS SUCCESSFULLY! Thank you so much for your help!

You might want to look at how java variable “copying” works aha

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

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
44 minutes ago, Cadiboo said:

You might want to look at how java variable “copying” works aha

I didn't just copy the reference. I am a CS major, I have an idea of what I'm doing. I constructed a new InventoryPlayer, but for some reason that one was still affected when I cleared the original. It seems like a problem with copying a reference, yet I did not copy the reference- thus why I am confused.

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.