EvilGood Posted February 28, 2017 Posted February 28, 2017 Hello, I'm trying to learn Minecraft modding and was busy with an exploding arrow. But I was getting an error in my event where it said I had to add a constructor method. I don't know why this happened. Could someone help me please? Here is the Code: package com.evilgood.github.events; import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.EntityArrow; import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class ExplodingArrowEvent extends EntityEvent { @SubscribeEvent public void onImpact(EntityJoinWorldEvent e) { if(e.getEntity() instanceof EntityArrow) { EntityArrow arrow = (EntityArrow) e.getEntity(); arrow.getEntityWorld().createExplosion(arrow, arrow.getPosition().getX(), arrow.getPosition().getY(), arrow.getPosition().getZ(), 10, true); } } } Thanks in advance, EvilGood. Quote
EvilGood Posted February 28, 2017 Author Posted February 28, 2017 I was looking through a document that said that I should extend it. I removed it now and it works, so thank you for that, but not the way I intended. I want it to explode on impact. Its now exploding when the arrow spawns in the world. Do I have to use another event or another command? And when do I extend public class? Thanks for helping, Evilgood. Quote
Failender Posted February 28, 2017 Posted February 28, 2017 first of all. If you want to listen to events you should be doing that inside an event listener class (if you dont know what im talking about google minecraft event handling you will find enough information there) You are using the EntityJoinWorld event. Which is the wrong event for listening for the impact of an arrow.. I dont even think there is such an event in forge. I was coding sth similar once, and I remember that I had to use the event for updating entities (LivingUpdateEvent), check if the arrow is inside an block (I see the EntityArrow class now has the property inTile, you will need reflection to access the private field) if that is != null you can create an explosion at the position of the arrow. Although I am not sure if using reflection is the right thing for something that isnt that experienced in java Greetz Failender 1 Quote
Draco18s Posted February 28, 2017 Posted February 28, 2017 On 2/28/2017 at 12:18 AM, EvilGood said: I was looking through a document that said that I should extend it. Expand What documentation where? Quote 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.
EvilGood Posted February 28, 2017 Author Posted February 28, 2017 This document. How do i get acces to the inTile function? forgeevents.html Quote
Failender Posted February 28, 2017 Posted February 28, 2017 On 2/28/2017 at 12:32 AM, Failender said: you will need reflection to access the private field Expand Quote
EvilGood Posted February 28, 2017 Author Posted February 28, 2017 Do you know a link or guide that would help me with reflection, because I'm kinda stuck at the moment. ^ Thanks for helping, Evilgood Quote
Failender Posted February 28, 2017 Posted February 28, 2017 http://lmgtfy.com/?q=java+reflection But reflection is not a good topic if you arent solid in the basics of java. But thats up 2 you Quote
EvilGood Posted February 28, 2017 Author Posted February 28, 2017 Thank you, I guess I'll start with something else then. Quote
Draco18s Posted February 28, 2017 Posted February 28, 2017 On 2/28/2017 at 11:28 AM, EvilGood said: This document. forgeevents.html Expand That is not what that document says. It is saying that EntityJoinWorldEvent extends EntityEvent already, not that YOU need to extend EntityEvent in order to use it. 1 Quote 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.
Recommended Posts
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.