Jump to content

ExplodingArrows


EvilGood

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

47 minutes ago, EvilGood said:

I was looking through a document that said that I should extend it.

What documentation where?

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.

Link to comment
Share on other sites

5 hours ago, EvilGood said:

This document. forgeevents.html

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.

  • Like 1

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.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.