Event where PLAYER kills entity

Started by StrawS on

Topic category: Advanced modding

Last seen on 21:41, 4. Jun 2020
Joined Jan 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Event where PLAYER kills entity

I know MCreator has a built in event where "entity dies" however, my problem is that I only want it to trigger a procedure when the PLAYER kills an entity. I've tested the entity dies, and if other mobs kill each other or another player kills an entity it counts for all players and still triggers the procedure.

I tried messing with some code, however mine doesn't work and keeps coming up with errors.

	@SubscribeEvent
	public void kill(LivingDeathEvent event) {
		if (event.source.getSourceOfDamage() instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer) source.getSourceOfDamage();
			int i = (int) entity.posX;
			int j = (int) entity.posY;
			int k = (int) entity.posZ;
			MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
			World world = server.worlds[0];
			java.util.HashMap<String, Object> dependencies = new java.util.HashMap<>();
			dependencies.put("x", i);
			dependencies.put("y", j);
			dependencies.put("z", k);
			dependencies.put("world", world);
			dependencies.put("entity", entity);
			this.executeProcedure(dependencies);
		}
	}

And here is the errors from the console:

C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_testproc1.java:43: error: source has private access in LivingDeathEvent
      if (event.source.getSourceOfDamage() instanceof EntityPlayer) {
               ^
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_testproc1.java:43: error: cannot find symbol
      if (event.source.getSourceOfDamage() instanceof EntityPlayer) {
                      ^
  symbol:   method getSourceOfDamage()
  location: variable source of type DamageSource
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_testproc1.java:44: error: cannot find symbol
         EntityPlayer player = (EntityPlayer) source.getSourceOfDamage();
                                              ^
  symbol:   variable source
  location: class mcreator_testproc1
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_testproc1.java:45: error: cannot find symbol
         int i = (int) entity.posX;
                       ^
  symbol:   variable entity
  location: class mcreator_testproc1
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_testproc1.java:46: error: cannot find symbol
         int j = (int) entity.posY;
                       ^
  symbol:   variable entity
  location: class mcreator_testproc1
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_testproc1.java:47: error: cannot find symbol
         int k = (int) entity.posZ;
                       ^
  symbol:   variable entity
  location: class mcreator_testproc1
C:\Pylo\MCreator179\forge\build\sources\main\java\mod\mcreator\mcreator_testproc1.java:55: error: cannot find symbol
         dependencies.put("entity", entity);
                                    ^
  symbol:   variable entity
  location: class mcreator_testproc1
7 errors
:compileJava FAILED
FAILURE: Build failed with an exception.

Last seen on 02:59, 17. Sep 2020
Joined Jun 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I would like to know this as…
Tue, 06/12/2018 - 21:09

I would like to know this as well.  What died and who killed it?