Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am searching for a ender pearl throw event so if it is throwed 10 times you get a achievement. Does somebody know wich event this is?And how to implement it?

Edited by MinecraftMart

EnderTeleportEvent gets posted when the actual teleportation is about to occur, and EntityJoinWorldEvent is posted when the EntityEnderPearl is spawned, but if you want to intercept it just as it is about to be thrown, then the event mentioned by diesieben07 is your best bet.

  • Author

So i did some testing and it didnt work

 

r is my cod:

package com.mart.achievements;

import ibxm.Player;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent.Action;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class ThrowingHandler {

public int PT = 0;

@SubscribeEvent
public void onItemThrow(PlayerInteractEvent p){
if (p.action.RIGHT_CLICK_BLOCK != null){
	System.out.println("Mart");
	PT = PT + 1;
}

if(PT == 10)
{

p.entityPlayer.addStat(Achievements.Enderpearl, 1);

}

}
}

 

And wich on if this should i use?

MinecraftForge.EVENT_BUS.register(new ThrowingHandler());
FMLCommonHandler.instance().bus().register(new ThrowingHandler());

"if (p.action.RIGHT_CLICK_BLOCK != null)" ... <cough>, umm, that's not how enumerations are typically checked.

 

I prefer to use a switch, but you can use if statements as well:

if (event.action ==  Action.RIGHT_CLICK_AIR) {
// do stuff
}

 

Look at the import for PlayerInteractEvent and you'll find out which event bus to register it with.

import net.minecraftforge.event.entity.player.PlayerInteractEvent;

  • Author

"if (p.action.RIGHT_CLICK_BLOCK != null)" ... <cough>, umm, that's not how enumerations are typically checked.

 

I prefer to use a switch, but you can use if statements as well:

if (event.action ==  Action.RIGHT_CLICK_AIR) {
// do stuff
}

 

Look at the import for PlayerInteractEvent and you'll find out which event bus to register it with.

import net.minecraftforge.event.entity.player.PlayerInteractEvent;

 

Then this happens

 

RIGHT_CLICK_AIR cannot be resolved or is not a field

You have to import the class. Press "ctrl-shift-o" if you are using Eclipse, it will automatically import what you need. Or hover your mouse over "Action" and see that Eclipse gives you some ideas of how to fix what's wrong, one of which should be to import the class.

"if (p.action.RIGHT_CLICK_BLOCK != null)" ... <cough>, umm, that's not how enumerations are typically checked.

 

I prefer to use a switch, but you can use if statements as well:

if (event.action ==  Action.RIGHT_CLICK_AIR) {
// do stuff
}

Import Action

 

Look at the import for PlayerInteractEvent and you'll find out which event bus to register it with.

import net.minecraftforge.event.entity.player.PlayerInteractEvent;

 

Then this happens

 

RIGHT_CLICK_AIR cannot be resolved or is not a field

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

Okay all errors gone!

 

But now on thing.. if you click in the air without trowing a ball it also activates te counter.. and it doesnt even trigger the achievement.

 

package com.mart.achievements;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;

public class ThrowingHandler {

public int PT = 0;

@SubscribeEvent
public void onItemThrow(PlayerInteractEvent event){
if (event.action ==  Action.RIGHT_CLICK_AIR){
	PT = PT + 1;
	System.out.println(PT);

	if(PT == 10)
	{
		System.out.println("BRIKT");
		event.entityPlayer.addStat(Achievements.Enderpearl, 1);
}



}

}
}

Gee golly willakers, you never checked to see if the item the player has in their hand is an ender pearl.

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.

  • Author

1) You probably want to store that counter per-player. Right now if 10 players throw an EnderPearl, the 10th one will get the achievement, even though he only threw one ender pearl.

2) Your probably want to store that counter at all. Right now, if a player throws 9 pearls and then logs out, the counter is reset.

3) RIGHT_CLICK_AIR fires every time the player right clicks air. You should check if he's holding an Ender pearl.

 

O wauw. Well i need some time to figure this out. Its really hard xD

 

  • Author

Its really hard xD

No it's not. This is fuckin basic java.

 

Well I aint that good at Java. A bit but i try to learn it. And it would be cool if you wanted to help me a bit. This is really wat i want to do even if i dont know how to.

Okay i cant figure this out. Is somebody willing to help me?

event.entityPlayer gives you the player, right? What methods are there in EntityPlayer that give you the item the player is holding? There are at least 2, but the easiest one is getHeldItem(), which returns an ItemStack or null if the player is empty-handed. So the steps look like this:

 

1. Get the ItemStack the player is holding

2. Check if it's null

3. If it's not null, check that the item in the ItemStack is an Ender Pearl

4. Increment the counter for your player

 

But as diesieben already pointed out, you are incrementing a single counter for all players, rather than a counter for each player. Perhaps you can tackle that another day after you have more Java under your belt, but if you're feeling adventurous, look into IExtendedEntityProperties.

  • Author

Okay i cant figure this out. Is somebody willing to help me?

event.entityPlayer gives you the player, right? What methods are there in EntityPlayer that give you the item the player is holding? There are at least 2, but the easiest one is getHeldItem(), which returns an ItemStack or null if the player is empty-handed. So the steps look like this:

 

1. Get the ItemStack the player is holding

2. Check if it's null

3. If it's not null, check that the item in the ItemStack is an Ender Pearl

4. Increment the counter for your player

 

But as diesieben already pointed out, you are incrementing a single counter for all players, rather than a counter for each player. Perhaps you can tackle that another day after you have more Java under your belt, but if you're feeling adventurous, look into IExtendedEntityProperties.

 

Thx! But now i got 1 little problem left.

 

package com.mart.achievements;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;

public class ThrowingHandler {

public int PT = 0;

@SubscribeEvent
public void onItemThrow(PlayerInteractEvent event, EntityPlayer k){
	EntityPlayer player = (EntityPlayer) event.entity;
	ItemStack heldItem = k.getHeldItem();

if (event.entityPlayer.getHeldItem() == null){
	return;
}
//THIS LINE What to say here?
else if(heldItem == Items.ender_pearl){

}

if(PT >= 10)
{
	event.entityPlayer.addStat(Achievements.Enderpearl, 1);
	System.out.println("BRIKT");

}

}
}

You are comparing a Itemstack:heldItem with a Item:Item.ender_pearl. If you want to compare those 2, you need to get the item out of the ItemStack and compare that with the item. Then you can update the PT variable.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

You are comparing a Itemstack:heldItem with a Item:Item.ender_pearl. If you want to compare those 2, you need to get the item out of the ItemStack and compare that with the item. Then you can update the PT variable.

 

Okay i get that but now i need to put it in code xD it tried some things but wouldnt work. Can you give me a example or show it me?

Can't you even do that? How do you even want to make a Minecraft mod that way?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

Can't you even do that? How do you even want to make a Minecraft mod that way?

 

 

Nope, But is that even important? I do what i like to do and i just need help. I already got a few achievements ready and they work so im already proud of that. Im only 14 years and i am a beginner at java. I dont see the need to know all the stuff when i only need help with the basics. When i have te code i figure out myself how they work and i can make more progress. Im just doin what i like and you can help or you can not. Your decision. But it would be awesome if you could help

Not to discourage you, little one, but their are many 30 year old java veterans who are struggling to write mods for Minecraft. And you think you can do it with no programming background or java experience whatsoever? You really should find a school class for programming unless you are a genius. Otherwise, your questions on the "basics" will just annoy people until you get booted. Think about it.

  • Author

Okay as i think about it it is pretty dumb yes. But its just i wanted to do this for a long time and now i finally understand the basics. I am learning java atm and try to understand every single bit of code. I will stop asking stupid questions and asking for basics. If you guyz could just help me finish this code that would be very awsome.

 

Sorry for the trouble i caused or if i anoyed people.

ItemStack.getItem() perhaps?

 

Use your god damn IDE for what it was built for.

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.

Chill guys, he's just a kid. Don't you remember what it was like when you first started coding? Everyone has to start somewhere.

 

@OP: That being said, you would do yourself a huge favor by stopping what you're doing and spending some time learning Java or any other language. Try the New Boston for video tutorials, and / or spend some time browsing through the tutorials on Oracle's website.

 

Regarding your problem, follow the steps I mentioned earlier:

// get the held ItemStack (you may need to substitute 'player' with 'event.player' or whatever:
ItemStack stack = player.getHeldItem();

// check if it's not null and the item contained therein is an ender pearl:
if (stack != null && stack.getItem() == Items.ender_pearl) {
// increment your counter or whatever else you want to do
}

This is very basic Java / IDE use, and as has been stated, this is not a Java help forum. Good luck.

  • Author

It worked! Thank you! And yes i will stop with the hard ones. But i already have some basic ones and will continue making them since their easy. I watch te new boston and we are also learning java in class now so i hope this mod will be cool one day :D Thank you

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.