Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved] On kill of zombie
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Betterjakers

[Solved] On kill of zombie

By Betterjakers, July 30, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

Hello! Does anyone know how to test for when a players kills a zombie? You're gonna hate me, I'm sorry, but I am on 1.6.4  :'(

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    746

coolAlias

coolAlias    746

  • Reality Controller
  • coolAlias
  • Members
  • 746
  • 2805 posts
Posted July 30, 2016

LivingDeathEvent, check if entity killed is instanceof EntityZombie and if the source of damage was caused by a player. This works in pretty much every version of Minecraft/Forge since at least 1.6.4.

  • Quote

width=228 height=100http://i.imgur.com/NdrFdld.png[/img]

Share this post


Link to post
Share on other sites

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

Alright, thanks! Would this work?

 

@ForgeSubscribe

public void onEntityDeath(LivingDeathEvent event) {

if(event.entityLiving instanceof EntityZombie) {

 

    System.out.println("Hello!");

   

}

   

    }

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    746

coolAlias

coolAlias    746

  • Reality Controller
  • coolAlias
  • Members
  • 746
  • 2805 posts
Posted July 30, 2016

If you registered the class containing that method to the Forge event bus, yeah, that's the basic premise and should be printing 'Hello!' every time a zombie dies.

  • Quote

width=228 height=100http://i.imgur.com/NdrFdld.png[/img]

Share this post


Link to post
Share on other sites

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

I did not register it to the forge event bus. How can I do that?

  • Quote

Share this post


Link to post
Share on other sites

coolAlias    746

coolAlias

coolAlias    746

  • Reality Controller
  • coolAlias
  • Members
  • 746
  • 2805 posts
Posted July 30, 2016

// during pretty much any of the mod init phases:
MinecraftForge.EVENT_BUS.register(new YourEventClass());

A quick Google search will bring up a lot of information on using Forge events that would be cumbersome to reproduce in forum posts.

  • Quote

width=228 height=100http://i.imgur.com/NdrFdld.png[/img]

Share this post


Link to post
Share on other sites

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

I did this, and it does not seem to work. I registered it to the event bus, so it should be working. Here is my class:

 

package mymod.quests;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraftforge.event.ForgeSubscribe;

import net.minecraftforge.event.entity.living.LivingDeathEvent;

 

public class Test {

 

@ForgeSubscribe

public void onEntityDeath(LivingDeathEvent event) {

if(event.entityLiving instanceof EntityPlayer) {

 

    System.out.println("Hello!");

   

}

   

    }

 

}

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
Posted July 30, 2016

In your initialization method you need to call MinecraftForge.EVENT_BUS.register(new EventHandlerClass());

  • Quote

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

What? In my main mod class, this is where I have it:

 

public static void init1( FMLInitializationEvent event )

{

MinecraftForge.EVENT_BUS.register(new SoundHandler());

MinecraftForge.EVENT_BUS.register(new Test());

}

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
Posted July 30, 2016

Now that I look at your code you are checking to see if the entity that died is an instance of EntityPlayer not entity Zombie. Sorry I read that post wrong. ANd to check if it was the player that killed it, use the damagesource object.

  • Quote

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

I changed it to EntityZombie but when a zombie dies, it does not say "Hello!" in console.

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
Posted July 30, 2016

What Minecraft version are you using.

  • Quote

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

1.6.4

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
Posted July 30, 2016

Why are you still using 1.6.4? And Instead of MinecraftForge.EVENT_BUS.register(new EventHandlerClass) use FMLCommonHandler.instance().bus().register(new EventHandlerClass);

  • Quote

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

coolAlias    746

coolAlias

coolAlias    746

  • Reality Controller
  • coolAlias
  • Members
  • 746
  • 2805 posts
Posted July 30, 2016

The first version you posted should be printing to the console each time a zombie dies. To test if your event handler is working at all, you can put a println at the very beginning of it:

@ForgeSubscribe
public void onEntityDeath(LivingDeathEvent event) {
  System.out.println("Entity died: " + event.entity);
}

If you're not getting any output at all, make sure you actually call that random static init1 method you posted... it'd be simpler just to register directly during one of the FML events.

 

Edit: No, don't use FMLCommonHandler event bus - that's the wrong bus for this event. Here's a tutorial  - please read it so we don't have to repeat the same information over and over again.

  • Quote

width=228 height=100http://i.imgur.com/NdrFdld.png[/img]

Share this post


Link to post
Share on other sites

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

Thanks! I did have the event bus in the wrong place. It now works. Now, how can I send a message to the killer?

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
Posted July 30, 2016

Oh thank you Cool Alias I completely forgot what goes where when dealing with Events thanks for the refresher, now if you'll excuse me I've got some reading to refresh on.

  • Quote

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

coolAlias    746

coolAlias

coolAlias    746

  • Reality Controller
  • coolAlias
  • Members
  • 746
  • 2805 posts
Posted July 30, 2016

No worries - that's the reason they finally consolidated the event buses, it was a mess keeping track of them.

 

@OP As we've said, you have to check if the DamageSource#getEntity is an EntityPlayer, then cast that entity to EntityPlayer so you can call I believe #addChatMessage to send them a chat - it's been a long time since I've looked at 1.6.4 and the chat methods have changed a lot since then, so you may have to look for it yourself.

  • Quote

width=228 height=100http://i.imgur.com/NdrFdld.png[/img]

Share this post


Link to post
Share on other sites

Betterjakers    0

Betterjakers

Betterjakers    0

  • Tree Puncher
  • Betterjakers
  • Members
  • 0
  • 39 posts
Posted July 30, 2016

Thanks you so much everyone, I got everything I wanted to done!

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • PtownCoderSchool
      [HIRING] Minecraft Modders

      By PtownCoderSchool · Posted 1 hour ago

      Hey all! I run a coding school with a lot of our students coming in looking to get introduced to coding through Minecraft and building their own mods! Whether you're using redstone and some simpler tools, or more advanced and working with Java, please don't hesitate to reach out with your experience!   This is a PAID role. Our students sign up for weekly sessions where you will assist them in making their ideas come to life and teaching them to code along the way.    Due to the pandemic, we are capable of hiring remotely, though you must be located in California.    Interested? Please message me so we can set-up an interview.    Must be be 15+ years old. 
    • brok4d
      [1.16.4] New particle texture for biome.

      By brok4d · Posted 1 hour ago

      I do not know if I explained well, what I try is to change the color of the water particles since my biome is all reddish, I have been looking at the classes of the forge particles and I do not see that it can be modified as I am doing, any Subjection, because you told me to update the forge version to give support, but so if I see that each time the private class is forge, and they cannot be accessed, and also the setParticleTextureIndex method with which it could be select the index of the texture of the particle, in the end I think it will get worse instead of better, if someone thinks otherwise than say it.
    • ryanmanrules
      Delete

      By ryanmanrules · Posted 1 hour ago

      Fixed
    • AdminCat
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By AdminCat · Posted 2 hours ago

      hhhhhhhhhhhhh  
    • AdminCat
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By AdminCat · Posted 3 hours ago

      How would I backdate I'm having the same issue here  
  • Topics

    • PtownCoderSchool
      0
      [HIRING] Minecraft Modders

      By PtownCoderSchool
      Started 1 hour ago

    • brok4d
      1
      [1.16.4] New particle texture for biome.

      By brok4d
      Started 11 hours ago

    • ryanmanrules
      0
      Delete

      By ryanmanrules
      Started 1 hour ago

    • Blake.bill
      12
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By Blake.bill
      Started September 9, 2020

    • sc0rich
      8
      how do I config mods in 1.16.4?

      By sc0rich
      Started Friday at 02:11 AM

  • Who's Online (See full list)

    • LexManos
    • <Gl33p_0r4nge>
    • brok4d
    • Eksity
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved] On kill of zombie
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community