So basically I want to add a new event that happens when a creeper blows up, but I cant edit the EntityCreeper file. I'm assuming its because it has a .class and not a .java file extension. How can I edit the Creepers (or any source files) code?
Extending the creeper class won't work if you want to change the behavior of the regular creeper. Extending a class creates a new class but doesn't change the behavior of the parent class.
To change behavior of vanilla code generally there are the following approaches. You should consider them in this order:
1) Look for public fields and methods that you can directly access. For example, the AI task lists of vanilla entities are public so you can actually clear the list and replace it entirely with your own task list -- so you can fully edit the AI of the vanilla entities.
2) Use events. Events have been created for many of the common points in the code where modders often want to change behavior. So if you want an entity to do something different when it dies, you can handle the LivingDeathEvent, etc. Many events are cancelable, meaning you can disrupt the vanilla behavior completely if you want, and the events also pass fields that can be directly edited (like the drops list in the LivingDropsEvent).
3) Use Java reflection. This allows you to access code that may not have public scope.
4) Advanced techniques -- access transformers, etc.
So, in your case it seems you want to do something when the creeper explodes. I think then you can handle the LivingDeathEvent and check if the entityLiving field is an instanceof EntityCreeper. If it is, then you know a creeper has just died and you can do what you want at that point.
Extending the creeper class won't work if you want to change the behavior of the regular creeper. Extending a class creates a new class but doesn't change the behavior of the parent class.
To change behavior of vanilla code generally there are the following approaches. You should consider them in this order:
1) Look for public fields and methods that you can directly access. For example, the AI task lists of vanilla entities are public so you can actually clear the list and replace it entirely with your own task list -- so you can fully edit the AI of the vanilla entities.
2) Use events. Events have been created for many of the common points in the code where modders often want to change behavior. So if you want an entity to do something different when it dies, you can handle the LivingDeathEvent, etc. Many events are cancelable, meaning you can disrupt the vanilla behavior completely if you want, and the events also pass fields that can be directly edited (like the drops list in the LivingDropsEvent).
3) Use Java reflection. This allows you to access code that may not have public scope.
4) Advanced techniques -- access transformers, etc.
So, in your case it seems you want to do something when the creeper explodes. I think then you can handle the LivingDeathEvent and check if the entityLiving field is an instanceof EntityCreeper. If it is, then you know a creeper has just died and you can do what you want at that point.
So another way I could do it would be to disable the vanilla creeper spawns, and copy the creeper files to a new class that I can edit.
So basically I want to add a new event that happens when a creeper blows up, but I cant edit the EntityCreeper file. I'm assuming its because it has a .class and not a .java file extension. How can I edit the Creepers (or any source files) code?
Thanks.
So create a new class and extend the original, then put the edits in there?
EDIT:
Ok, now I have this, which extends the entitycreeper class. It should spawn CreeperEgg entities when a creeper dies, but doesnt. Any ideas?
Because this code is never getting run. If you had your own EntityCreeper, that used this class, then yes, it would run, but that is not the case.
Just use the LivingDeathEvent, and check if the entity is an instance of EntityCreeper. If so, make your changes.
Extending the creeper class won't work if you want to change the behavior of the regular creeper. Extending a class creates a new class but doesn't change the behavior of the parent class.
To change behavior of vanilla code generally there are the following approaches. You should consider them in this order:
1) Look for public fields and methods that you can directly access. For example, the AI task lists of vanilla entities are public so you can actually clear the list and replace it entirely with your own task list -- so you can fully edit the AI of the vanilla entities.
2) Use events. Events have been created for many of the common points in the code where modders often want to change behavior. So if you want an entity to do something different when it dies, you can handle the LivingDeathEvent, etc. Many events are cancelable, meaning you can disrupt the vanilla behavior completely if you want, and the events also pass fields that can be directly edited (like the drops list in the LivingDropsEvent).
3) Use Java reflection. This allows you to access code that may not have public scope.
4) Advanced techniques -- access transformers, etc.
So, in your case it seems you want to do something when the creeper explodes. I think then you can handle the LivingDeathEvent and check if the entityLiving field is an instanceof EntityCreeper. If it is, then you know a creeper has just died and you can do what you want at that point.
So another way I could do it would be to disable the vanilla creeper spawns, and copy the creeper files to a new class that I can edit.
Just did some tinkering and the code works, now I just have to make it work with the creepers.