Find if Player is the source of damage/is the killer?

Started by Jaxfirebus on Mon, 09/12/2016 - 22:56

Topic category: Advanced modding

Last seen on 01:12, 24. Jul 2017
Joined Sep 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Find if Player is the source of damage/is the killer?
Mon, 09/12/2016 - 22:56

This has been driving me into a wall, I've searched google and visited multiple sites but none of them provided answers of any value.

This isn't what i was trying to do with the code, but it's just the test to see if it would work.

if (event.source.getSourceOfDamage() instanceof EntityPlayer){  

world.setBlockState(new BlockPos(i, j, k), Blocks.GOLD_BLOCK.getDefaultState(), 3);

}

Instead of it working, i got this:

warning: [options] bootstrap class path not set in conjunction with -source 1.6
C:\Pylo\MCreator170\forge\build\sources\main\java\mod\mcreator\mcreator_GlobalEventsTestEnvironmentMod.java:26: error: source has private access in LivingDeathEvent
            if (event.source.getSourceOfDamage() instanceof EntityPlayer) {
                     ^
1 error
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I've tried multiple ways of doing it, but i can't figure it out. Please, someone help me out here.

Last seen on 01:12, 24. Jul 2017
Joined Sep 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Nevermind, found out how to
Fri, 09/16/2016 - 16:53

Nevermind, found out how to fix it.

Here's how i did it:

[spoiler]

if (!(event.getEntityLiving() instanceof EntityPlayer)){
if(event.getEntityLiving().getAttackingEntity() instanceof EntityPlayer){ 
[/spoiler]