Jump to content

RS785

Members
  • Posts

    7
  • Joined

  • Last visited

Posts posted by RS785

  1. I'm now facing an issue when serializing and deserializing, I better know how NBT works but when using Gson I can only serialize to a file which looks like this: 

    {"mainInventory":[{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}}],"armorSlots":[{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}},{"tagMap":{"id":{"data":"minecraft:air"},"Count":{"data":1}}}]}

    But when it comes to deserialization, Gson doesn't work...

    I won't upload the full log but important bits I cannot understand:

    [11:32:13.645] [Server thread/ERROR] [EventBus/EVENTBUS]: Exception caught during firing event: Unable to invoke no-args constructor for interface net.minecraft.nbt.INBT. Register an InstanceCreator with Gson for this type may fix this problem.
    	Index: 1
    	Listeners:
    		0: NORMAL
    		1: ASM: class com.example.examplemod.Event.PlayerEvents onPlayerChangeDimension(Lnet/minecraftforge/event/entity/player/PlayerEvent$PlayerChangedDimensionEvent;)V
    java.lang.RuntimeException: Unable to invoke no-args constructor for interface net.minecraft.nbt.INBT. Register an InstanceCreator with Gson for this type may fix this problem.
    Caused by: java.lang.UnsupportedOperationException: Interface can't be instantiated! Interface name: net.minecraft.nbt.INBT
    

    Thank you in advance, and sorry for the long waiting time.

  2. Hello,

    I'd like to serialize and deserialize players' inventories in order to have 1 inventory per dimension (Overworld, nether, end, my_custom_dimension).

    I currently have the PlayerEvent.PlayerChangedDimensionEvent event set-up and the custom dimension, I don't know how could I serialize & deserialize the inventories.

    I've already tried Gson without any success, it kept on crashing.

    Thank you in advance for the help :)

        @SubscribeEvent
        public static void onPlayerChangeDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
            PlayerEntity p = event.getPlayer();
    
            RegistryKey<World> from = event.getFrom();
            RegistryKey<World> to = event.getTo();
    
            // Save the player's inventory (from)
            // . . .
    
            // Retrieve the player's inventory (to)
            // . . .
    
        }

     

×
×
  • Create New...

Important Information

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