Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.2]Crash on player.addChatComponentMessage


Recommended Posts

So for some reason, i'm getting a npe in in my sendChatToPlayer function, but it was working previously. Here's all it is :


    public static void sendChatToPlayer(EntityPlayer player, String message)


    player.addChatComponentMessage(new ChatComponentText(message));



And the stacktrace is :


Caused by: java.lang.NullPointerException

at net.minecraft.entity.player.EntityPlayerMP.addChatComponentMessage(EntityPlayerMP.java:987) ~[EntityPlayerMP.class:?]

at mymod.util.ChatMessageHandler.sendChatToPlayer(ChatMessageHandler.java:33) ~[ChatMessageHandler.class:?]


The line it fails at is :

        this.playerNetServerHandler.sendPacket(new S02PacketChat(p_146105_1_));

in the EntityPlayerMP class in the net.minecraft.blah.blah bit.


Whats going wrong?

Link to comment
Share on other sites

I personally wasnt calling that, the  player.addChatComponentMessage(new ChatComponentText(message)) calls it. As in, the function addChatComponentMessage is as follows :


    public void addChatComponentMessage(IChatComponent p_146105_1_)


        this.playerNetServerHandler.sendPacket(new S02PacketChat(p_146105_1_));


Link to comment
Share on other sites

I call sendChatToPlayer(EntityPlayer player, String message) in er, almost everywhere, but the problem is in my "setSkill" method in my ExtendedEntityProperties. The method is :


public void setSkill(Skill lookup, int i, EntityPlayer player)


Side side = FMLCommonHandler.instance().getEffectiveSide();

RSLogging.log(this.getClass(), "Increasing level");


if (side == Side.CLIENT)


RSLogging.log(this.getClass(), "So not doing anything");




this.SkillAmounts[lookup.ordinal()] = i;

this.ExpAmounts[lookup.ordinal()] = this.limits[i - 1];

RSChatMessageHandler.sendChatToPlayer(player, "Congratulations, you are now " + this.getSkill(lookup) +" " + lookup.name().toLowerCase());




(RSLogging.log takes the class and a message, and prints the class, effective side and message)

Link to comment
Share on other sites

Hrm, that's weird. First of all though: Do not use getEffectiveSide, only for debugging purposes (if even then). It is slow and may be unreliable. Use


instead. "But I don't have a world available!", you complain. Yes, you do. Every entity has one. Every TileEntity has one. And so on and so forth. You almost never have no world available.


Regarding your problem: I really don't know. Try debugging with your IDE and see what's null (and why).

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.

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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • i found it guys
    • So i just bought a RLcraft server for me and my friends to play on. I launched it and it is working fine but it tells me that i need to download all the mods i go to mods and press "minecraft forge" and nothing shows up that i can open files. If anyone have a suggestion i would need the help. This is the server hosting i  used 
    • i did it in 1.12.2 not walking for me can anyone help me get it pls???  
    • Got the rotation working. I had to look at LivingEntityRenderer#render and setupRotations a little more closely, and I realized that I needed to change the custom entity's yBodyRot and yBodyRotO.  private static boolean renderingCustomEntity = false; private static CustomEntity customEntity; private static void refreshCustomEntity(LocalPlayer localPlayer, LivingEntity livingEntity) { if (customEntity == null || customEntity.isRemoved()) { customEntity = ModEntities.CUSTOM_ENTITY.get().create(localPlayer.clientLevel); } if (!customEntity.level.dimension().equals(livingEntity.level.dimension())) { customEntity.discard(); } } @SubscribeEvent public static void replaceMobModel(RenderLivingEvent.Pre<LivingEntity, EntityModel<LivingEntity>> event) { LocalPlayer localPlayer = Minecraft.getInstance().player; if (localPlayer != null && event.getEntity() instanceof Mob mob) { if (/* put your own condition here */) { if (!renderingCustomEntity) { try { renderingCustomEntity = true; event.setCanceled(true); refreshCustomEntity(localPlayer, mob); // (truth be told, my custom entity does not have a "head", so these lines aren't needed) // customEntity.setYHeadRot(mob.getYHeadRot()); // customEntity.yHeadRotO = mob.yHeadRotO; customEntity.setYBodyRot(mob.yBodyRot); customEntity.yBodyRotO = mob.yBodyRotO; customEntity.setPose(mob.getPose()); Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(customEntity).render( customEntity, customEntity.yBodyRot, event.getPartialTick(), event.getPoseStack(), event.getMultiBufferSource(), event.getPackedLight() ); } finally { renderingCustomEntity = false; } } } } }   As shown in my code, if the mob whose model is replaced moves to a different dimension, I unload the custom entity with Entity#discard and then reinitialize it on the next tick. I wonder if I also have to unload the custom entity when the mob it is "replacing" dies.
  • Topics

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.