Jump to content

[Solved] [1.7.2] Is there a ender pearl throw event?


MinecraftMart

Recommended Posts

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());

Link to comment
Share on other sites

"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;

Link to comment
Share on other sites

"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

Link to comment
Share on other sites

"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/

Link to comment
Share on other sites

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);
}



}

}
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

}

}
}

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.