Jump to content

MC 1.7.10 [SOLVED] Custom drop not dropping from an other mods block


Recommended Posts

Posted

I'm trying to add cherries as drop to the cherry trees from Biomesoplenty.

But it doesn't work and i don't know why.

 

If i do this:

public class TemExtraBOPDrops {

@SubscribeEvent
public void TemBOPloot(HarvestDropsEvent event) 
{
	Block block = event.block; 
	int random = randomWithRange(0,2);
	if (block ==Blocks.leaves){
		if (random == 1){
			event.drops.add(new ItemStack(TemItems.cherry));
		}

	}
   
}
public static int randomWithRange(int min, int max){
	Random rand= new Random();
	int randomNum = rand.nextInt((max-min)+1)+min;
	return randomNum;
}

}

then the cherry drops.

But when i change it to this:

public class TemExtraBOPDrops {

@SubscribeEvent
public void TemBOPloot(HarvestDropsEvent event) 
{
	Block block = event.block;
	//ItemStack stack = new ItemStack(block); 
	int random = randomWithRange(0,2);
	//if (stack.getItemDamage() == 1 || stack.getItemDamage() == 3 ){
	if (block ==BOPCBlocks.leaves3){
		if (random == 1){
			event.drops.add(new ItemStack(TemItems.cherry));
		}

	}
   
}
public static int randomWithRange(int min, int max){
	Random rand= new Random();
	int randomNum = rand.nextInt((max-min)+1)+min;
	return randomNum;
}

}

then it doesn't drop.

Posted

i tried this now:

public class TemExtraBOPDrops {

@SubscribeEvent
public void TemBOPloot(BreakEvent event) 
{
	System.out.println("event has occured"); 
	Block block = event.block;
	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;
	ItemStack stack = new ItemStack(TemItems.cherry);
	EntityItem item = new EntityItem(world,x,y,z, stack);
	if (block == BOPCBlocks.leaves3){
		if (event.blockMetadata==1){
			world.spawnEntityInWorld(item);
		}
	}
	//ItemStack stack = new ItemStack(block); 
	//int random = randomWithRange(0,2);
	//if (stack.getItemDamage() == 1 || stack.getItemDamage() == 3 ){
	//if (block ==BOPCBlocks.leaves3){
		//System.out.println("De juiste bladeren!!"); 
		//if (random == 1){
			//event.drops.add(new ItemStack(TemItems.cherry));
		//}

	//}
   
}
public static int randomWithRange(int min, int max){
	Random rand= new Random();
	int randomNum = rand.nextInt((max-min)+1)+min;
	return randomNum;
}

}

This seems to work somehow a bit.

The cherries do spawn but the spawnrate is randomly.

I was expecting dropping it every time since i did not provide a spawnrate! weird...

Posted

Don't create the item stack and entity if you don't intend to spawn it in the world, you're just adding extra work for the garbage collector.

(Won't fix your problem, but it makes your code cleaner)

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.

Posted

Show your BOPCBlocks class.

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.

Posted

Jup that's right, it's from the API.

 

Ok i did a few more test with this:

public class TemExtraBOPDrops {

@SubscribeEvent
public void TemBOPloot(HarvestDropsEvent event) 
{
	System.out.println("event has occured"); 
	Block block = event.block;
	int random = randomWithRange(0,2);
	//if (block == Blocks.leaves){
	if (block == BOPCBlocks.leaves3){
		System.out.println("leaves!!"); 
		if (random == 1){
			event.drops.add(new ItemStack(TemItems.cherry));
		}
	} 
}
public static int randomWithRange(int min, int max){
	Random rand= new Random();
	int randomNum = rand.nextInt((max-min)+1)+min;
	return randomNum;
}

}

 

Like it is now it doesn't work. whenever i break a block that is a biomesoplenty leaves block, the "event has occured" does not show up in the console.

If i do break an other block it does shows up. So the event does work on whatever block as long as it isn't a leaves block from BOP.

That's weird i think. Why would it not trigger that event on those leaveblocks?

And because the harvestdropsevent does not occur on those leaveblocks the whole thing does nothing.

When i switch it to Blocks.leaves ( just to test it) , everything works fine and i get the "leaves!!" message too in the console.

 

So let's say i would not check the right leaves like diesieben07 mentioned (it could be, but it's not), then the event still triggers and should show me the message "event has occured".

 

I really hope someone can help me with this. I do not understand why this isn't working. It should work, but it doesn't...... :(

 

EDIT:I took a look into the BlockBOPLeaves.class and i saw it doesn't have a -harvestBlock- method. Not sure if this is causing the problem.

 

Posted

Ok i made it work with the breakevent. It works fine now, but now i also want to check for a specific block.

BOPCBlocks.leaves3 has 4 types and i only want to check for 1 and 3.

How do i get them?

I tried this:

public class TemExtraBOPDrops {

@SubscribeEvent
public void TemBOPloot(BreakEvent event) 
{
	System.out.println("event has occured"); 
	Block block = event.block;
	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;
	//int meta = world.getBlockMetadata(x, y, z);
	//if (meta ==1 || meta ==3){
	//System.out.println("meta found");
	if (block==BOPCBlocks.leaves3 ){
		System.out.println("condition met"); 
		int random = randomWithRange(0,10);
		if (random == 1){
			ItemStack stack = new ItemStack(TemItems.cherry);
			EntityItem item = new EntityItem(world,x,y,z, stack);
			world.spawnEntityInWorld(item);
			}
		}
	//}
}
public static int randomWithRange(int min, int max){
	Random rand= new Random();
	int randomNum = rand.nextInt((max-min)+1)+min;
	return randomNum;
}

}

 

nevermind, found it:

@SubscribeEvent
public void TemBOPloot(BreakEvent event) 
{
	System.out.println("event has occured"); 
	Block block = event.block;
	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;
	int meta = block.getDamageValue(world, x, y, z);
	if (meta ==1 || meta ==3){
	System.out.println("meta found");
	if (block==BOPCBlocks.leaves3 ){
		System.out.println("condition met"); 
		int random = randomWithRange(0,10);
		if (random == 1){
			ItemStack stack = new ItemStack(TemItems.cherry);
			EntityItem item = new EntityItem(world,x,y,z, stack);
			world.spawnEntityInWorld(item);
			}
		}
	}
}
public static int randomWithRange(int min, int max){
	Random rand= new Random();
	int randomNum = rand.nextInt((max-min)+1)+min;
	return randomNum;
}

}

I looked into the breakevent class and found -block.getDamageValue(world, x, y, z)-

I think my problem is now solved.

I am looking at their source code and I don't see a reason why the event shouldn't fire.

The leaveblocks from bop do not have a harvestdropsevent, so instead i used the breakevent and this works.

Thank you!

Posted

You should check for block first, then meta.

Also, you shouldn't use

block.getDamageValue

, you should use

world.getBlockMetadata

.

The default implementation of the former calls Block#damageDropped, which is not necessarily the same as the block's current metadata value.

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.

Posted

You should check for block first, then meta.

Also, you shouldn't use

block.getDamageValue

, you should use

world.getBlockMetadata

.

The default implementation of the former calls Block#damageDropped, which is not necessarily the same as the block's current metadata value.

Yeah you're right i should check the block first then meta.

I tried world.getBlockMetadata before (that was my first idea too) but that doesn't do anything.

That's why i looked into the breakevent class i and found the block.getDamageValue.

Posted

I tried world.getBlockMetadata before (that was my first idea too) but that doesn't do anything.

 

What do you mean it doesn't do anything?

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.

Posted

 

What do you mean it doesn't do anything?

well, it does do something for sure, but not the thing i want. Let's say it doesn't work then.

 

So i ran a small test to know why that doesn't work.

So when i do it like this:

public class TemExtraBOPDrops {

@SubscribeEvent
public void TemBOPloot(BreakEvent event) {
	//System.out.println("event has occured"); 
	Block block = event.block;
	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;
	if (block==BOPCBlocks.leaves3 ){
		//int meta = block.getDamageValue(world, x, y, z);
		int meta = world.getBlockMetadata(x, y, z);
		System.out.println(meta); 
		if (meta ==1 || meta ==3){
			int random = randomWithRange(0,10);
			if (random == 1){
				ItemStack stack = new ItemStack(TemItems.cherry);
				EntityItem item = new EntityItem(world,x,y,z, stack);
				world.spawnEntityInWorld(item);
				}
			}
		}
	}
public static int randomWithRange(int min, int max){
	Random rand= new Random();
	int randomNum = rand.nextInt((max-min)+1)+min;
	return randomNum;
}

}

 

then depending wich of the 2 leaves i "break" the variable meta returns 11 or 9. (sometimes it returns 1 or 3 too, but very rare)

Because i need to check if it's 1 or 3 , the if statement will never return true.

I don't know why it returns 11 and 9, maybe my code is wrong or maybe i really need to use block.getDamageValue(world, x, y, z)

And i'm pretty sure the metadata of those block are 1 and 3.

You have more experience in this, so maybe you know why it is returning 11 and 9.

 

EDIT:i'm completely confused now. I did the /give command to see what happens if i enter 9 or 11 as value.

I found out that /give playername biomesoplenty:leaves3 10 9 give me the right leaves

I also found out when replacing meta 9 with 1, 5, 9, 13, 17, 21, and so on gives the same block (they do not stack).

 

Posted

Ahhh.

 

Gotcha.  See, "it doesn't work" isn't sufficient to understand the problem.  "The blocks have a metadata of 11 or sometimes 9" however, is.

 

You need some bitwise operators.

 

int meta = world.getBlockMetadata(x, y, z) & 3;

 

That'll strip of the decay checking flags.

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.

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.

Announcements



×
×
  • Create New...

Important Information

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