Jump to content

[Events / NBT] Loading not working


Lordmau5
 Share

Recommended Posts

I use some event system, to add some functions to the player death and player spawn.

 

If the player dies, it writes something to it's nbt.

Also, after checking it with .getKey, it IS there.

 

At spawn, I check again, if it's there.

But it isn't?!

 

 

Code:

@ForgeSubscribe
public void onEntitySpawn(EntityJoinWorldEvent event)
    {
	if(event.world.isRemote)
	{
		return;
	}
        if(event.entity instanceof EntityPlayer)
        {
        	EntityPlayer thePlayer = (EntityPlayer) event.entity;
        	
        	NBTTagCompound nbtTag = new NBTTagCompound();
        	thePlayer.writeToNBT(nbtTag);

        	System.out.println("Getting entity data...");
        	System.out.println("Has Key DI? : " + nbtTag.hasKey("DeathImprover"));
        	if(nbtTag.hasKey("DeathImprover"))
        	{
        		NBTTagCompound DI = nbtTag.getCompoundTag("DeathImprover");
        		System.out.println("Has DI Compound");
        		nbtTag.removeTag("DeathImprover");
        	}
        }
    }

@ForgeSubscribe
public void onEntityDeath(LivingDeathEvent event)
{
	if(event.entity.worldObj.isRemote)
	{
		return;
	}
	if(event.entity instanceof EntityPlayer)
	{
		EntityPlayer thePlayer = (EntityPlayer) event.entity;

		System.out.println("Player Died!");

		NBTTagCompound entityTempTag = new NBTTagCompound();
		thePlayer.writeToNBT(entityTempTag);

		entityTempTag.setBoolean("DeathImprover", true);
		System.out.println("Saved the Vars!");
		System.out.println("has DI: " + entityTempTag.hasKey("DeathImprover"));

		event.setCanceled(true);
	}
}

Link to comment
Share on other sites

Still telling me on spawn, that the key doesn't exist...

 

Changed code:

@ForgeSubscribe
public void onEntitySpawn(EntityJoinWorldEvent event)
    {
	if(event.world.isRemote)
	{
		return;
	}
        if(event.entity instanceof EntityPlayer)
        {
        	EntityPlayer thePlayer = (EntityPlayer) event.entity;
        	
        	NBTTagCompound wholeTag = thePlayer.getEntityData();
        	
        	NBTTagCompound nbtTag = wholeTag.getCompoundTag(thePlayer.PERSISTED_NBT_TAG);

        	System.out.println("Getting entity data...");
        	System.out.println("Has Key DI? : " + nbtTag.hasKey("DeathImprover"));
        	if(nbtTag.hasKey("DeathImprover"))
        	{
        		NBTTagCompound DI = nbtTag.getCompoundTag("DeathImprover");
        		System.out.println("Has DI Compound");
                
        		nbtTag.removeTag("DeathImprover");
        	}
        }
    }

@ForgeSubscribe
public void onEntityDeath(LivingDeathEvent event)
{
	if(event.entity.worldObj.isRemote)
	{
		return;
	}
	if(event.entity instanceof EntityPlayer)
	{
		EntityPlayer thePlayer = (EntityPlayer) event.entity;

		System.out.println("Player Died!");
		NBTTagList tempTag = new NBTTagList();
		thePlayer.inventory.writeToNBT(tempTag);

		NBTTagCompound entityTempTag = thePlayer.getEntityData();
		thePlayer.writeToNBT(entityTempTag);

		NBTTagCompound persistTag = entityTempTag.getCompoundTag(thePlayer.PERSISTED_NBT_TAG);
		persistTag.setTag("DeathImprover", tempTag);

		System.out.println("Saved the Vars!");

		event.setCanceled(true);
	}
}

Link to comment
Share on other sites

As test, I want to write an boolean variable and check it later.

 

What I actually want to do is, that if my inventory contains a special item (e.g. an egg) it should save my inventory and load it again on spawn, independent of how the gamerule keepInventory is.

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried to install client forge on my linux desktop. But after "installation" it's missing forge[version].jar file in .minecraft/versions. I tried java 11 and 8 environment with same result. Here link to log file from installation: https://drive.google.com/file/d/1vtg9NT-WX5ilb1aNUvZlOv54gKWJuaT1/view?usp=share_link. I don't know what to do. I give for every directory permissions that I don't think that is issue. I will try check older versions if universal file work. Debian 11 (kernel 5.10)
    • I recently got error 1 in the launcher, so I restarted the .minecraft. After restarting it, I can't get the Forge 1.19.2 - 43.1.1 installer to run, I tried other versions and I get the same result, it opens a black box that closes instantly and nothing happens. I already tried to restart my pc, minecraft, update and reinstall java, run vanilla 1.19.2 and more recent versions of the game, disable Windows Firewall and antivirus and I still haven't solved it. Many times I installed forge and never ran into this problem. If I could receive assistance I would be very grateful.  
    • Here's the default loot table for gravel block: { "type": "minecraft:block", "pools": [ { "rolls": 1.0, "bonus_rolls": 0.0, "entries": [ { "type": "minecraft:alternatives", "children": [ { "type": "minecraft:item", "conditions": [ { "condition": "minecraft:match_tool", "predicate": { "enchantments": [ { "enchantment": "minecraft:silk_touch", "levels": { "min": 1 } } ] } } ], "name": "minecraft:gravel" }, { "type": "minecraft:alternatives", "conditions": [ { "condition": "minecraft:survives_explosion" } ], "children": [ { "type": "minecraft:item", "conditions": [ { "condition": "minecraft:table_bonus", "enchantment": "minecraft:fortune", "chances": [ 0.1, 0.14285715, 0.25, 1.0 ] } ], "name": "minecraft:flint" }, { "type": "minecraft:item", "name": "minecraft:gravel" } ] } ] } ] } ] } This is a finicky loot table. If I add anything to it, nothing drops. I've added pools, entries, children ... you name it. Does anyone know the particulars about this table? I mean, periodically gravel drops flint instead of a gravel block. I understand the condition that could drop flint if the block survives an explosion. Otherwise, it drops the gravel block itself. I would like to further understand why the use of `children` and the set of `chance` values given in the explosion child entry. What I do understand is that `"type" : "minecraft:alternatives"` means that if this child/entry is successful, then it stops generating loot for this entry/pool. How often does the flint drop and is that taken care of in another location? Is that in a `"condition" : "minecraft:table_bonus"` loot table? Hmmm... I'll have to go take a look and see if there is something called table_bonus.json.
    • No mod is working. Im trying to create a pack for some friends but cant get past this. I reinstalled Forge and I got a complete install pop up like normal   [29Jan2023 14:17:58.884] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, Oddie23110, --version, 1.19.3-forge-44.1.8, --gameDir, C:\Users\Oddie\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Oddie\AppData\Roaming\.minecraft\assets, --assetIndex, 2, --uuid, d7db39d1b1f940ac841852e76fe1844c, --accessToken, ????????, --clientId, M2JmY2FlYTktNzE1OC00NzYwLThlMzUtNGIxYzA1MzcwNTli, --xuid, 2535431288182209, --userType, msa, --versionType, release, --width, 1600, --height, 900, --launchTarget, forgeclient, --fml.forgeVersion, 44.1.8, --fml.mcVersion, 1.19.3, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20221207.122022] [29Jan2023 14:17:58.889] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.8+10.0.8+main.0ef7e830 starting: java version 17.0.3 by Microsoft; OS Windows 10 arch amd64 version 10.0 [29Jan2023 14:17:59.094] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/Oddie/AppData/Roaming/.minecraft/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2392!/ Service=ModLauncher Env=CLIENT [29Jan2023 14:17:59.498] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\Oddie\AppData\Roaming\.minecraft\libraries\net\minecraftforge\fmlcore\1.19.3-44.1.8\fmlcore-1.19.3-44.1.8.jar is missing mods.toml file [29Jan2023 14:17:59.503] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\Oddie\AppData\Roaming\.minecraft\libraries\net\minecraftforge\javafmllanguage\1.19.3-44.1.8\javafmllanguage-1.19.3-44.1.8.jar is missing mods.toml file [29Jan2023 14:17:59.507] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\Oddie\AppData\Roaming\.minecraft\libraries\net\minecraftforge\lowcodelanguage\1.19.3-44.1.8\lowcodelanguage-1.19.3-44.1.8.jar is missing mods.toml file [29Jan2023 14:17:59.513] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\Oddie\AppData\Roaming\.minecraft\libraries\net\minecraftforge\mclanguage\1.19.3-44.1.8\mclanguage-1.19.3-44.1.8.jar is missing mods.toml file [29Jan2023 14:17:59.653] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: flywheel. Using Mod File: C:\Users\Oddie\AppData\Roaming\.minecraft\mods\flywheel-forge-1.19.2-0.6.8.a.jar [29Jan2023 14:17:59.654] [main/INFO] [net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator/]: Found 1 dependencies adding them to mods collection [29Jan2023 14:18:00.624] [main/INFO] [mixin/]: Compatibility level set to JAVA_17 [29Jan2023 14:18:00.629] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeclient' with arguments [--version, 1.19.3-forge-44.1.8, --gameDir, C:\Users\Oddie\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Oddie\AppData\Roaming\.minecraft\assets, --uuid, d7db39d1b1f940ac841852e76fe1844c, --username, Oddie23110, --assetIndex, 2, --accessToken, ????????, --clientId, M2JmY2FlYTktNzE1OC00NzYwLThlMzUtNGIxYzA1MzcwNTli, --xuid, 2535431288182209, --userType, msa, --versionType, release, --width, 1600, --height, 900] [29Jan2023 14:18:00.827] [main/WARN] [mixin/]: Error loading class: net/minecraft/client/renderer/texture/TextureAtlas$Preparations (java.lang.ClassNotFoundException: net.minecraft.client.renderer.texture.TextureAtlas$Preparations) [29Jan2023 14:18:00.827] [main/WARN] [mixin/]: @Mixin target net.minecraft.client.renderer.texture.TextureAtlas$Preparations was not found flywheel.mixins.json:atlas.SheetDataAccessor [29Jan2023 14:18:00.840] [main/WARN] [mixin/]: Error loading class: me/jellysquid/mods/sodium/client/render/chunk/data/ChunkRenderData$Builder (java.lang.ClassNotFoundException: me.jellysquid.mods.sodium.client.render.chunk.data.ChunkRenderData$Builder) [29Jan2023 14:18:00.840] [main/WARN] [mixin/]: @Mixin target me.jellysquid.mods.sodium.client.render.chunk.data.ChunkRenderData$Builder was not found flywheel.mixins.json:instancemanage.SodiumChunkRenderDataMixin [29Jan2023 14:18:00.853] [main/WARN] [mixin/]: Error loading class: com/mojang/math/Matrix3f (java.lang.ClassNotFoundException: com.mojang.math.Matrix3f) [29Jan2023 14:18:00.854] [main/WARN] [mixin/]: @Mixin target com.mojang.math.Matrix3f was not found flywheel.mixins.json:matrix.Matrix3fMixin [29Jan2023 14:18:00.855] [main/WARN] [mixin/]: Error loading class: com/mojang/math/Matrix4f (java.lang.ClassNotFoundException: com.mojang.math.Matrix4f) [29Jan2023 14:18:00.856] [main/WARN] [mixin/]: @Mixin target com.mojang.math.Matrix4f was not found flywheel.mixins.json:matrix.Matrix4fMixin [29Jan2023 14:18:00.974] [main/WARN] [mixin/]: Error loading class: net/minecraft/client/renderer/texture/TextureAtlas$Preparations (java.lang.ClassNotFoundException: net.minecraft.client.renderer.texture.TextureAtlas$Preparations) [29Jan2023 14:18:03.993] [pool-3-thread-1/INFO] [net.minecraft.util.datafix.DataFixers/]: Building unoptimized datafixer [29Jan2023 14:18:05.173] [Render thread/WARN] [mixin/]: Error loading class: com/mojang/math/Quaternion (java.lang.ClassNotFoundException: com.mojang.math.Quaternion) [29Jan2023 14:18:05.175] [Render thread/FATAL] [mixin/]: Mixin apply failed flywheel.mixins.json:matrix.PoseStackMixin -> com.mojang.blaze3d.vertex.PoseStack: org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException Unexpecteded ClassMetadataNotFoundException whilst transforming the mixin class: [MAIN Applicator Phase -> flywheel.mixins.json:matrix.PoseStackMixin -> Apply Methods -> (Lcom/mojang/math/Quaternion;)Lcom/jozufozu/flywheel/util/transform/TransformStack;:multiply -> Transform LVT -> var=quaternion -> desc=Lcom/mojang/math/Quaternion;] org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException: Unexpecteded ClassMetadataNotFoundException whilst transforming the mixin class: [MAIN Applicator Phase -> flywheel.mixins.json:matrix.PoseStackMixin -> Apply Methods -> (Lcom/mojang/math/Quaternion;)Lcom/jozufozu/flywheel/util/transform/TransformStack;:multiply -> Transform LVT -> var=quaternion -> desc=Lcom/mojang/math/Quaternion;]     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformMethod(MixinTargetContext.java:491) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyNormalMethod(MixinApplicatorStandard.java:532) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyMethods(MixinApplicatorStandard.java:518) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyMixin(MixinApplicatorStandard.java:386) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:325) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.TargetClassContext.apply(TargetClassContext.java:383) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:365) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:250) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.service.modlauncher.MixinTransformationHandler.processClass(MixinTransformationHandler.java:131) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.launch.MixinLaunchPluginLegacy.processClass(MixinLaunchPluginLegacy.java:131) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClassWithFlags(ILaunchPluginService.java:156) ~[modlauncher-10.0.8.jar:10.0.8+10.0.8+main.0ef7e830]     at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:88) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:120) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.TransformingClassLoader.maybeTransformClassBytes(TransformingClassLoader.java:50) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:113) ~[securejarhandler-2.1.6.jar:?]     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?]     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.6.jar:?]     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.6.jar:?]     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.6.jar:?]     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]     at com.mojang.blaze3d.systems.RenderSystem.<clinit>(RenderSystem.java:83) ~[1.19.3-forge-44.1.8.jar:?]     at net.minecraft.client.main.Main.m_239872_(Main.java:174) ~[1.19.3-forge-44.1.8.jar:?]     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3-forge-44.1.8.jar:?]     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.8.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?]     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] Caused by: org.spongepowered.asm.mixin.throwables.ClassMetadataNotFoundException: com.mojang.math.Quaternion     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformSingleDescriptor(MixinTargetContext.java:983) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformSingleDescriptor(MixinTargetContext.java:943) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformLVT(MixinTargetContext.java:544) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     at org.spongepowered.asm.mixin.transformer.MixinTargetContext.transformMethod(MixinTargetContext.java:450) ~[mixin-0.8.5.jar:0.8.5+Jenkins-b310.git-155314e6e91465dad727e621a569906a410cd6f4]     ... 36 more  
  • Topics

×
×
  • Create New...

Important Information

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