Jump to content

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


winnetrie

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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

 

Link to comment
Share on other sites

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.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • How can I add drops when killing an entity? Now there are no drops. How can I add an @override to change the attack speed to 1.6 and show "when in main hand...attack damage,...attack speed"? also, how can I make the item enchantable? 
    • Ok. Thanks. by the way, will this crash in any circumstances? public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) { if (entity instanceof LivingEntity){ LivingEntity victim = (LivingEntity) entity; if(!victim.isDeadOrDying() && victim.getHealth()>0){ victim.setHealth(0); return true; } } return false; }  
    • You shouldn't be extracting the mod .jar, just place it in your mods folder.
    • so basically another rundown of my probelm. Im the admin of a 1.20.1 modded server. Were using forge 47.2.0 but tested this issue in other forge versions too on sevrer and client side. so the forge version isnt the issue. The bug happens in following instances. Were using the attacks of the jujutsucraft mod by orca normally. And for everyone that stands there nothing changes. But everyone who wasnt in the chunks before or who relogins again those chunks will appear invisible for the most part. I tried fixing this be removing and adding following mods in many combinations. Embeddium, canary, memoryleakfix, ai improvements, Krypton reforges, better chunkloading, radium reforged, embeddium plus, farsight, betterchunkloading, oculus I tested most of these mods alone and in differents combinations with each other and without the mods. What i noticed is zhat when i removed  . most invisible chunks will return or semi return. and only ine or two chunks stay invisible. I rechanged those mids mostly on the cöient side but also some in the serveside. Ir most likely isnt an issue with another non performance mod since i noticed this thing with embeddium. Ans also the problem wasnt there im the beginning of the server. Granted since then we updated some of the mods that add content and their lib mod. But i went to every big mods discord and community that we have and i didnt find someone else havinf that chunk problem. Heres the link to a video of the Problem. https://streamable.com/9v1if2     heres the link to the modlist: https://ibb.co/myF8dtX     Pleaee im foghting for months with this problem. All the performance mods kn the modlist are for sure not the issue i tested without all of them.
    • It looks like you're only setting the health if the thing you are hitting is a player.  
  • Topics

×
×
  • Create New...

Important Information

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