HELLO people! So I have made a new arrow that is fired from a new skeleton. Everything works correctly, however the death message is not correct. When the player is killed by a new skeleton with this new arrow, it says "death.newarrow".
Now, I know this can be fixed with a simple
ModLoader.addLocalization("death.newarrow, "Player was shot by New Skeleton");
, however, I do not know how to extract the player's username to be displayed in the message (so that instead of saying "Player was shot by New Skeleton" it would say "Stormister was shot by New Skeleton", or whatever the player's username is). Can anyone help me out? I am using Forge.
ModLoader.getMinecraftInstance().thePlayer.username;
and to put that in your mod use
ModLoader.addLocalization("death.newarrow", ModLoader.getMinecraftInstance().thePlayer.username + " was shot by New Skeleton");
I Have not tested it but it should work
If you can get the EntityPlayer or EntityPlayerMP (not sure about EntityPlayerSP), you can do player.username. (Assuming the variable player is equal to the instance of EntityPlayer or EntityPlayerMP.
ModLoader.getMinecraftInstance().thePlayer.username;
and to put that in your mod use
ModLoader.addLocalization("death.newarrow", ModLoader.getMinecraftInstance().thePlayer.username + " was shot by New Skeleton"); I Have not tested it but it should work
Hey thanks so much. That worked
EDIT: Nevermind :/ I get a Null Pointer Exception when I recompile and test the mod. Could this be because I am not actually logged in with a Minecraft account? If so then I will try reobfuscating and testing in the normal launcher.
A username is still assigned to the player in MCP so that wouldn't be an issue. Post the error report and code please.
Rollback Post to RevisionRollBack
“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
A username is still assigned to the player in MCP so that wouldn't be an issue. Post the error report and code please.
Here is the error report:
Minecraft has crashed!
----------------------
Minecraft has stopped running because it encountered a problem; Failed to start game
A full error report has been saved to C:\Users\Matt\Desktop\MCP\Rediscovered Mod 1.4.6\jars\.\crash-reports\crash-2013-01-14_15.47.06-client.txt - Please include a copy of that file (Not this screen!) if you report this crash to anyone; without it, they will not be able to help fix the crash
--- BEGIN ERROR REPORT 758fd3f8 --------
Full report at:
C:\Users\Matt\Desktop\MCP\Rediscovered Mod 1.4.6\jars\.\crash-reports\crash-2013-01-14_15.47.06-client.txt
Please show that file to Mojang, NOT just this screen!
Generated 1/14/13 3:47 PM
-- System Details --
Details:
Minecraft Version: 1.4.6
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_10, Oracle Corporation
Java VM Version: Java HotSpot™ 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 977034168 bytes (931 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v7.25 FML v4.6.12.511 Minecraft Forge 6.5.0.467 4 mods loaded, 4 mods active
mcp [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized
FML [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
Forge [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
Rediscovered [Minecraft Rediscovered Mod] (bin) Unloaded->Constructed->Pre-initialized->Errored
LWJGL: 2.4.2
OpenGL: Intel® HD Graphics Family GL version 3.0.0 - Build 8.15.10.2353, Intel
Is Modded: Definitely; Client brand changed to 'forge,fml'
Type: Client (map_client.txt)
Texture Pack: Default
Profiler Position: N/A (disabled)
Vec3 Pool Size: ~~ERROR~~ NullPointerException: null
java.lang.NullPointerException
at RediscoveredMod.mod_Rediscovered.load(mod_Rediscovered.java:214)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:478)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
at com.google.common.eventbus.EventBus.post(EventBus.java:268)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
at com.google.common.eventbus.EventBus.post(EventBus.java:268)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:83)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:656)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:207)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:456)
at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)
at net.minecraft.client.Minecraft.run(Minecraft.java:744)
at java.lang.Thread.run(Unknown Source)
--- END ERROR REPORT d9d89999 ----------
And here is the code (after removing anything not relevant/uneeded):
The Null Pointer Exception points to the line which holds the "ModLoader.addLocalization" bit. Also I believe I should note that I am using forge. Using ModLoader functions should work, however, since ModLoader is now implemented in Forge, therefore that should not be a problem.
Minecraft has stopped running because it encountered a problem; Failed to start game
A full error report has been saved to C:\Users\Matt\Desktop\MCP\Rediscovered Mod 1.4.6\jars\.\crash-reports\crash-2013-01-14_15.47.06-client.txt - Please include a copy of that file (Not this screen!) if you report this crash to anyone; without it, they will not be able to help fix the crash
--- BEGIN ERROR REPORT 758fd3f8 --------
Full report at:
C:\Users\Matt\Desktop\MCP\Rediscovered Mod 1.4.6\jars\.\crash-reports\crash-2013-01-14_15.47.06-client.txt
Please show that file to Mojang, NOT just this screen!
Generated 1/14/13 3:47 PM
-- System Details --
Details:
Minecraft Version: 1.4.6
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_10, Oracle Corporation
Java VM Version: Java HotSpot™ 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 977034168 bytes (931 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v7.25 FML v4.6.12.511 Minecraft Forge 6.5.0.467 4 mods loaded, 4 mods active
mcp [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized
FML [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
Forge [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
Rediscovered [Minecraft Rediscovered Mod] (bin) Unloaded->Constructed->Pre-initialized->Errored
LWJGL: 2.4.2
OpenGL: Intel® HD Graphics Family GL version 3.0.0 - Build 8.15.10.2353, Intel
Is Modded: Definitely; Client brand changed to 'forge,fml'
Type: Client (map_client.txt)
Texture Pack: Default
Profiler Position: N/A (disabled)
Vec3 Pool Size: ~~ERROR~~ NullPointerException: null
java.lang.NullPointerException
at RediscoveredMod.mod_Rediscovered.load(mod_Rediscovered.java:214)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:478)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
at com.google.common.eventbus.EventBus.post(EventBus.java:268)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
at com.google.common.eventbus.EventBus.post(EventBus.java:268)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:83)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:656)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:207)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:456)
at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)
at net.minecraft.client.Minecraft.run(Minecraft.java:744)
at java.lang.Thread.run(Unknown Source)
--- END ERROR REPORT d9d89999 ----------
And here is the code (after removing anything not relevant/uneeded):
The Null Pointer Exception points to the line which holds the "ModLoader.addLocalization" bit. Also I believe I should note that I am using forge. Using ModLoader functions should work, however, since ModLoader is now implemented in Forge, therefore that should not be a problem.
What is line 214 of the mod file without everything removed? As Pelep said, you should be using LanguageRegistry for localizations, not ModLoader.
Rollback Post to RevisionRollBack
“Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination."
this one worked for me. instead of the ModLoader.addLocalization, use this:
LanguageRegistry.instance().addStringLocalization("death.parrow", "%1$s was shot by skeleton.")
Okay, if that is working then there is some string formatting going on. By the looks of it, you're not doing it yourself so there must be some background code going on. "%1" would be referencing the player's name at some point in the code if that is doing what you're claiming it to do.
As for the original poster's error.
When you're loading the mod you're making reference to the player variable that probably isn't actually created until the game is done loading. That's where the null point exception is coming in, when you make to reference to "getMinecraftInstance().thePlayer" the variable "thePlayer" is most probably return as null, which when you make reference to the variable "username", its parent is null, which throws a null point exception.
Please note that i am making the assumption that the variable "thePlayer" isn't initiated when you call it in the load, you can prove this assumption by either printing the variable "thePlayer" or by making a variable that holds "thePlayer", print that or put a break point in the code and inspect it.
What is line 214 of the mod file without everything removed? As Pelep said, you should be using LanguageRegistry for localizations, not ModLoader.
Line 214 is the line with the ModLoader.addLocalization piece of code. And yea I didn't realize that LanguageRegistry also had an addLocalization feature.
Yes... never use ModLoader.***, even though it's there, it's only there for compatibility reasons and is only affective on the client, not the server. Also, your using ModLoader code, switch to full FML code. If you need help just ask!
Now, I know this can be fixed with a simple , however, I do not know how to extract the player's username to be displayed in the message (so that instead of saying "Player was shot by New Skeleton" it would say "Stormister was shot by New Skeleton", or whatever the player's username is). Can anyone help me out? I am using Forge.
ModLoader.getMinecraftInstance().thePlayer.username;
and to put that in your mod use
ModLoader.addLocalization("death.newarrow", ModLoader.getMinecraftInstance().thePlayer.username + " was shot by New Skeleton");
I Have not tested it but it should work
Hey thanks so much. That workedEDIT: Nevermind :/ I get a Null Pointer Exception when I recompile and test the mod. Could this be because I am not actually logged in with a Minecraft account? If so then I will try reobfuscating and testing in the normal launcher.
together they are powerful beyond imagination."
----------------------
Minecraft has stopped running because it encountered a problem; Failed to start game
A full error report has been saved to C:\Users\Matt\Desktop\MCP\Rediscovered Mod 1.4.6\jars\.\crash-reports\crash-2013-01-14_15.47.06-client.txt - Please include a copy of that file (Not this screen!) if you report this crash to anyone; without it, they will not be able to help fix the crash
--- BEGIN ERROR REPORT 758fd3f8 --------
Full report at:
C:\Users\Matt\Desktop\MCP\Rediscovered Mod 1.4.6\jars\.\crash-reports\crash-2013-01-14_15.47.06-client.txt
Please show that file to Mojang, NOT just this screen!
Generated 1/14/13 3:47 PM
-- System Details --
Details:
Minecraft Version: 1.4.6
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_10, Oracle Corporation
Java VM Version: Java HotSpot™ 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 977034168 bytes (931 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v7.25 FML v4.6.12.511 Minecraft Forge 6.5.0.467 4 mods loaded, 4 mods active
mcp [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized
FML [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
Forge [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
Rediscovered [Minecraft Rediscovered Mod] (bin) Unloaded->Constructed->Pre-initialized->Errored
LWJGL: 2.4.2
OpenGL: Intel® HD Graphics Family GL version 3.0.0 - Build 8.15.10.2353, Intel
Is Modded: Definitely; Client brand changed to 'forge,fml'
Type: Client (map_client.txt)
Texture Pack: Default
Profiler Position: N/A (disabled)
Vec3 Pool Size: ~~ERROR~~ NullPointerException: null
java.lang.NullPointerException
at RediscoveredMod.mod_Rediscovered.load(mod_Rediscovered.java:214)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:478)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
at com.google.common.eventbus.EventBus.post(EventBus.java:268)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
at com.google.common.eventbus.EventBus.post(EventBus.java:268)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:83)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:656)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:207)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:456)
at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)
at net.minecraft.client.Minecraft.run(Minecraft.java:744)
at java.lang.Thread.run(Unknown Source)
--- END ERROR REPORT d9d89999 ----------
And here is the code (after removing anything not relevant/uneeded):
mod_Blank:
The Null Pointer Exception points to the line which holds the "ModLoader.addLocalization" bit. Also I believe I should note that I am using forge. Using ModLoader functions should work, however, since ModLoader is now implemented in Forge, therefore that should not be a problem.
What is line 214 of the mod file without everything removed? As Pelep said, you should be using LanguageRegistry for localizations, not ModLoader.
together they are powerful beyond imagination."
Okay, if that is working then there is some string formatting going on. By the looks of it, you're not doing it yourself so there must be some background code going on. "%1" would be referencing the player's name at some point in the code if that is doing what you're claiming it to do.
As for the original poster's error.
When you're loading the mod you're making reference to the player variable that probably isn't actually created until the game is done loading. That's where the null point exception is coming in, when you make to reference to "getMinecraftInstance().thePlayer" the variable "thePlayer" is most probably return as null, which when you make reference to the variable "username", its parent is null, which throws a null point exception.
Please note that i am making the assumption that the variable "thePlayer" isn't initiated when you call it in the load, you can prove this assumption by either printing the variable "thePlayer" or by making a variable that holds "thePlayer", print that or put a break point in the code and inspect it.
Holy shizz this actually worked. I have no IDEA how but it actually works. Thank you
Author of the Clarity, Serenity, Sapphire & Halcyon shader packs for Minecraft: Java Edition.
My Github page.
The entire Minecraft shader development community now has its own Discord server! Feel free to join and chat with all the developers!
I love Minecraft
You may need to add a variable at the top of your class that is:
private static Minecraft mc;
Add this above it, if it doesnt work on servers:
@SideOnly(Side.CLIENT)
Example Code:
"Hello, " + this.mc.thePlayer.username + "!"
Hope I helped!