Jump to content

Recommended Posts

Posted

Hello,

maybe its a very simple question, but I havent used Forge long.

Iam coding a mod for a server.

But how can I get the player, which is killing the Enderman?

 

@SubscribeEvent
    public void onKill(LivingDeathEvent event) {
        if (event.entityLiving.getName().equalsIgnoreCase(Minecraft.getMinecraft().thePlayer.getName())) {
            Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Test1"));
            Entity e = event.entity;
            if (e instanceof EntityEnderman) {
                i++;
              	Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("§7Enderman killed: §e§l" + i));
            }
        }
    }

 

The player will get the message if an Enderman dies, but it doesn't matter who killed the enderman.

But the player should only get the message, if he kills an Enderman.

How can I do this?

 

I am using Forge 1.8.9-11.15.1.2318

 

Thanks.

(Sorry for my bad english)

Posted

You cannot call Minecraft.getMinecraft().thePlayer if you are on the server side.

As you're already using the LivingDeathEvent you can call event.getSource().getTrueSource() to get the player who killed the enderman.

Posted
1 hour ago, MadeByProxxy said:

if (event.entityLiving.getName().equalsIgnoreCase(Minecraft.getMinecraft().thePlayer.getName())) {

Oh jesus christ on a crutch. Everything about this line is awful.

 

1) Never convert to strings to do comparisons

2) You're reaching across logical sides (this will hard-crash a dedicated server)

3) This is (attempting) to check if the entity that died is the player

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
5 hours ago, Angercraft said:

You cannot call Minecraft.getMinecraft().thePlayer if you are on the server side.

As you're already using the LivingDeathEvent you can call event.getSource().getTrueSource() to get the player who killed the enderman.

Okay, thank you. How can I use .getSource? It doesnt exists with me.

 

3 hours ago, Draco18s said:

Oh jesus christ on a crutch. Everything about this line is awful.

Yeah I know.. I looked at that line again and its really stupid..

Thanks

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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