Jump to content

[1.14.4] Small issue with LivingDeathEvent


kaiser_

Recommended Posts

Hello!

I am working with a LivingDeathEvent where I check if the causer of the kill is a player. This code actually worked before, but somehow after a few more testing it just "glitched". I'm already trying for a day now to figure this out. I've worked with IItemHandler when this happened, if it helps anything. What am I missing?

I've read other topics as well, but no luck.

 

Here is the code for this:

public static void onMobKill(LivingDeathEvent e) {
		if(!(e.getSource().getTrueSource() instanceof PlayerEntity)) {
			return;
		}
		// do something here
}

 

Also another question with this: Will this work on servers as well? As far as I know, this event gets called each time someone kills an entity, and I'm changing player attached capability when this happens. I really don't want this to cause problems on servers.

If I'm wrong somewhere, let me know!

Link to comment
Share on other sites

4 minutes ago, kaiser_ said:

Will this work on servers as well?

IIRC this event is only fired on the server.

And regardless, "will it work on the server?" is always true for things dealing with "game state" (and things dying is definitely game state information).

 

Pretty much the answer is:
"Does it involve visuals (textures, models), keyboard input, or sound files? No? Then it works on the server."

Another way to tell is "is the 'client' in the package name?"

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.

Link to comment
Share on other sites

18 minutes ago, Draco18s said:

IIRC this event is only fired on the server.

And regardless, "will it work on the server?" is always true for things dealing with "game state" (and things dying is definitely game state information).

 

Pretty much the answer is:
"Does it involve visuals (textures, models), keyboard input, or sound files? No? Then it works on the server."

Another way to tell is "is the 'client' in the package name?"

Thanks for Your answer!

Let me explain a bit further: so let's say I have a friend online on one of my modded servers, my friend kills a pig for example, and in my capability this was the requirement for my capability to be changed. I meant if this is possible to have this event be called on my client as well even when I am not the killer of the pig, and if it does how would I be able to fix this?

 

Link to comment
Share on other sites

3 hours ago, kaiser_ said:

if this is possible to have this event be called on my client as well

No. Use packets.

Why does your client need to know this information?

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.

Link to comment
Share on other sites

5 hours ago, Draco18s said:

No. Use packets.

Thank You!

 

I wonder if You would have an answer to my first problem in the topic as well, as if that problem remains, I can't even experiment anything that You've said.

It was pretty late when I wrote this topic, so if it needs more explanation, let me know!

Link to comment
Share on other sites

Your one about saving information for each player?

You already have an answer.

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.

Link to comment
Share on other sites

27 minutes ago, Draco18s said:

You already have an answer.

I meant this:

18 hours ago, kaiser_ said:

Hello!

I am working with a LivingDeathEvent where I check if the causer of the kill is a player. This code actually worked before, but somehow after a few more testing it just "glitched". I'm already trying for a day now to figure this out. I've worked with IItemHandler when this happened, if it helps anything. What am I missing?

I've read other topics as well, but no luck.

 

Here is the code for this:


public static void onMobKill(LivingDeathEvent e) {
		if(!(e.getSource().getTrueSource() instanceof PlayerEntity)) {
			return;
		}
		// do something here
}

 

Just to explain it a bit further: this statement returns true even if the player landed the last hit, and it pretty much worked for a few more tests, then it somehow changed. 

That was my main problem.

Link to comment
Share on other sites

I have no idea what the problem even was. Glad you figured it out though.

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.

Link to comment
Share on other sites

19 minutes ago, Draco18s said:

I have no idea what the problem even was.

The problem is with the statement asking if the "killer" of the entity is a player or not. It supposed to return false in the code below, if the player was the source, Sadly it returns true in every way

 

public static void onMobKill(LivingDeathEvent e) {
		if(!(e.getSource().getTrueSource() instanceof PlayerEntity)) {
			return;
		}
		// do something here
}

 

I've also tried to reverse the statement like below, but the problem still remains

public static void onMobKill(LivingDeathEvent e) {
		if(e.getSource().getTrueSource() instanceof PlayerEntity) {
			// do something here
		}
}

 

Any ideas? 

Link to comment
Share on other sites

Not sure.

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.

Link to comment
Share on other sites

I would be glad if someone who had this problem and solved it would answer. This thing is on my head for a few days now, and I can't really proceed with my code without this part.

If You know some similar statement like this, I would be happy as well.

 

however, I'll keep trying. 

Link to comment
Share on other sites

Use the debugger, check what object is coming back as the TrueSource and why its triggering your boolean check incorrectly.

  • Thanks 1

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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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