Jump to content

(1.7.10) How to change how many item drop from a block and the numbers of Items


Recommended Posts

Posted

I would like it so that when you a block it can drop multiple item like when you mine redstone ore it drop more than one  redstone, I also would like to make it so a block drop multiple different items like feathers and sticks.

 

currently i am using:

 

public Item getItemDropped(int par1, Random random,int par2)

{

    return Item.feather;

}

Posted
  On 5/25/2015 at 12:49 PM, Oswejo said:

I would like it so that when you a block it can drop multiple item like when you mine redstone ore it drop more than one  redstone, I also would like to make it so a block drop multiple different items like feathers and sticks.

 

currently i am using:

 

public Item getItemDropped(int par1, Random random,int par2)

{

    return Item.feather;

}

getDrops()

Posted

my code now is

@Overrride

public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune){

      ArrayList<ItemStack> stack = super.getDrop(world, x, y, z, metadata, fortune);

      stack.add(new ItemStack(items.feather, 1));

      stack.add(new ItemStack(items.stick, 1));

      stack.add(new ItemStack(items.string, 1));

      stack.add(new ItemStack(items.egg, 1));

      Return stack;

}

 

So i get all the items but it also drops the block that I break and i don't want this to happen also is there a way of changing the drops for a set number to 1-5 drop. If so how would I code the Random amount dropped

 

Posted

After i Added a random drop amount  when i destroy the block my game crashes.

 

Crash report

 

  Reveal hidden contents

 

 

this is the Nest.class

 

  Reveal hidden contents

 

Posted
  On 5/25/2015 at 2:40 PM, Oswejo said:

After i Added a random drop amount  when i destroy the block my game crashes.

 

Crash report

 

  Reveal hidden contents

 

 

this is the Nest.class

 

  Reveal hidden contents

 

Of course you got this crash, because you're calling the method itself from itself...

Posted
  Quote
Of course you got this crash, because you're calling the method itself from itself...

 

where is it doing this as it was all working before and now I'm just confusing myself

Posted

Ok i now understand what you mean by it calls itself but if How do i cahnge this as i need both of them for it to function so is it something wrong with my naming

 

Posted

I saw the mistake sorry for all the hassle and by both I meant

 

public ArrayList<ItemStack> getDrops(World world, int x,int y, int z, int metadata, int fortune){

    ArrayList<ItemStack> stack = getDrops(world, x, y, z, metadata, fortune);

Posted

You dont really need that here is an example of what youre trying to make I drop them one at a time but you can drop as many as you want. Modify for your purposes. Also Thank you btn is ----> that a way----> ;-)

 

 

public class BlockAcornLeaves extends CustomBlock{public BlockAcornLeaves(Material material) {	super(material);	this.setHardness(0.1f);	this.setResistance(5.0f);	this.setStepSound(soundTypeGrass);}public boolean isOpaqueCube(){	return false;}@Overridepublic boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {	{		ItemStack itemstack = entityPlayer.getCurrentEquippedItem();		if(!world.isRemote && itemstack != null && itemstack.getItem() == CommonProxy.acornHarvester )//world.isRemote == false - has to be false otherwise you do it twice once for server and once for client		{			this.dropRandomAcorns(world, x, y, z);		}		return false;	}}//when the block is right clicked, drop several randomly coloured acorns and rarely an acorn leaf blockprivate void dropRandomAcorns(World world, int x, int y, int z){	int maxRand = 100000;	Random random = new Random();	//probability that the item will be dropped, out of 10000	//the drop rate of each item is independent and does not affect the others.	int dropProbabilities[] = {			35000, //red acorn			20000, //white acorn			2500, //blue acorn			2000, //black acorn			1500, //yellow acorn			500, //green acorn			100,	//pink acorn			10,	//acorn leaf block	};	for(int i = 0; i < dropProbabilities.length; i++){		Item droppedItem = null;		int r = MathHelper.getRandomIntegerInRange(random, 0, maxRand);		if(r < dropProbabilities[i]){			switch(i){			case 0:				droppedItem = CommonProxy.acornRed; 				break;			case 1:				droppedItem = CommonProxy.acornWhite; 				break;			case 2:				droppedItem = CommonProxy.acornBlue; 				break;			case 3:				droppedItem = CommonProxy.acornBlack; 				break;			case 4:				droppedItem = CommonProxy.acornYellow; 				break;			case 5:				droppedItem = CommonProxy.acornGreen; 				break;			case 6: 				droppedItem = CommonProxy.acornPink; 				break;			case 7: 				droppedItem = Item.getItemFromBlock(CommonProxy.blockAcornLeaves); 				break;			}			if(droppedItem != null){				ItemStack myItemStack = new ItemStack(droppedItem, 1);				EntityItem entityitem = new EntityItem(world, x, y, z, myItemStack);				entityitem.delayBeforeCanPickup = 10;				world.spawnEntityInWorld(entityitem);			}		}	}}

 

Posted
  On 5/25/2015 at 3:27 PM, Oswejo said:

Ok i now understand what you mean by it calls itself but if How do i cahnge this as i need both of them for it to function so is it something wrong with my naming

 

You mean....by creating an empty list?

 

      @Override
      public ArrayList<ItemStack> getDrops(World world, int x,int y, int z, int metadata, int fortune){
         //don't call super, that drops the block.
         //Don't call this function, that causes an infinite loop.
         //Create a new list.
         ArrayList<ItemStack> stack = new ArrayList<ItemStack>();

         stack.add(...);
         return stack;
      }

 

Also, Thornack's post is useless.

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

No need for insults Draco, please keep the forum positive. I gave him an example of how to get whatever item or block he wants to drop when a block is clicked while holding an item based on a random probability. He can modify it as he sees fit to suit his needs. Its easy to change the code to drop a random number of the chosen item... I wouldnt call that useless as my class works.

Posted
  On 5/30/2015 at 5:56 PM, Thornack said:

No need for insults Draco, please keep the forum positive. I gave him an example of how to get whatever item or block he wants to drop when a block is clicked while holding an item based on a random probability. He can modify it as he sees fit to suit his needs. Its easy to change the code to drop a random number of the chosen item... I wouldnt call that useless as my class works.

 

Which is useless, because he's breaking the block, not activating it. His problem has nothing to do with generating a random item, but with correctly implementing the

getDrops

function, which the code you posted doesn't use.

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.