Jump to content

Getting different items from different stages, [Crops]


Recommended Posts

Posted

Hello,

 

I was wondering if there was a way to have different items on different stages.

Like, when the paprika stage is at green you get green paprika, when it's at the yellow stage, yellow, etc...

 

So could anyone give me a hint/tell me how i need to get it done.

That would be very apprecciated ;-)

 

When you have questions, ask me

 

Here is my code of  my paprika food if needed (bell pepper):

http://pastebin.com/GB9dC6Bd

Creator of the Master Chef Mod and many more to come.

 

If I helped you, please click the 'thank you' button.

Posted

What he means is that in the getDrops you can check in which state the plant curently is. Somthing like:

 

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
{
if (p_149650_1_ == stateofgreen){
  return modfile.greenpaprikaitem;
}
return null;
}

this code will probably not quite work but I hope you can figure it out yourself from here (haven't worked with crops since 1.3)

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Posted

Not sure but I think you'll actualy have to use something like this:

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return p_149650_1_ == 7 ? this.func_149865_P() : item;

    }

 

where 7 is the metadata of the block and item is the item it should give. Just expland that for the 4 states (not grown, green, yellow, red)

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Posted

Okey,

 

How do i expand it? like

 

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return p_149650_1_ == 7 ? this.func_149865_P() : Morefood.foodGreenPaprika: Morefood.foodYellowPaprika;

    }

Or how does it work?

I've tried several things and i can't get it to work, it always gives me 'green paprika' and at full growth 'wheat'.

Creator of the Master Chef Mod and many more to come.

 

If I helped you, please click the 'thank you' button.

Posted

Okay, here's the thing, this is your own custom block so you can code anything you want in Java.  But it is also a Minecraft mod so you need to respond to those method calls that Minecraft Forge makes to your blocks.  As diesieben07 says, the real entry to your block code is the getDrops() method.  The other methods are used within your block and you can use those as well (like getItemDropped()), but not necessarily needed. In getDrops() you can do whatever you want -- it is your own Java code after all.  You could drop something, or spawn another entity, or add an achievement or whatever.

 

So the only thing you have to do is change the returned value based on the growth stage.  You already can tell the stage of the crop based on the metadata, and the nice thing about the getDrops() method is that the metadata is passed as one of the parameters.  So just do some conditional statements (like if statements) to check the metadata and return the type of item you want to drop.

 

Make sense?

 

In the end, the point is that you can code anything you want, but you need to put it in the getDrops() method because that is what will get called when Minecraft needs the drops.  After that it is just Java, the possibilities are endless.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

{

        return customGetDropFunction(p_149650_1_);

}

 

public Item customGetDropFunction(int p_149650_1_){

if (p_149650_1_ == 5){

  return modfile.greenpaprika;

}else if (p_149650_1_ == 6){

  return modfile.yellowpaprika;

}else if (p_149650_1_ == 7){

  return modfile.redpaprika

}else{

  return modfile.paprikaseeds;

}

}

 

This should work if you replace the Items. What the others are saying is correct as long as the getItemDropped is refering to those functions, this changes that so these functions are in theory not requered anymore.

 

You should also know how it works from the code but basicly what it does is if the user breaks the crop block it will run the getItemDropped function this function has the metadata as the variable  "p_149650_1_" which you pass to your custom getDrop function which than has if else statements to check the metadata and drop the correct item.

 

NOTE untested!

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Posted

As I said. You need to override getDrops.

 

Just tested the code I sent and it works! YOU DO NOT HAVE TO OVERRIDE getDrops!

 

If you're stupid enought to still belive so please get of the internet. If you want prove I can post the code I used so you could test it.

 

Here's reason you don't need getDrops:

getDrops is a function called within the getItemDropped. the function getItemDropped can not be repleaced as it´s a function Minecraft uses to see which item/block has to be dropped getDrops is a "easy" way of chaning the drop!

 

If you look at the getItemDropped of the minecraft block BlockCrops:

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return p_149650_1_ == 7 ? this.func_149865_P() : this.func_149866_i();

    }

 

As you can see if you know ANYTHING about java this only call the functions getDrop (this.func_149865_P() in the case of BlockCrops) and this.func_149866_i() is the drop of the seed this function only returns this item, thus it could be used if you want but in this specific case it would only call getDrop() if the metadata was 7 which would be useless this statment could either be changed in the "if statment" in getItemDropped or be replaced with a custom getDrops (which is easier in this case!).

 

Sorry if you got offended but please check your facts before telling that something will not work is necessary if it's not!

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Posted

That only works if you want it to drop 1 item. If you want more control about your drops, you should override

getDrops(params)

.

 

this only call the functions getDrops (this.func_149865_P() in the case of BlockCrops)

BTW, I know Java. I atleast know that

getDrops(params)

isn't called

this.func_149865_P()

in the BlockCrops class...

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/

Posted

That only works if you want it to drop 1 item. If you want more control about your drops, you should override

getDrops(params)

.

 

this only call the functions getDrops (this.func_149865_P() in the case of BlockCrops)

BTW, I know Java. I atleast know that

getDrops(params)

isn't called

this.func_149865_P()

in the BlockCrops class...

 

Good you know such a complicated function name!

 

But the amount of items is controlled by:

public int quantityDropped(Random p_149745_1_)

    {

        return 1;

    }

 

and can easliy be manipulated (depending on metadata!) So that shouldn't be a problem!

 

Also i could not find a way to specify a drop amount in the getDrops() function I will asume you're right and it is possible with it but just for my informaition could you tell me how to specify such a thing?

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Posted

I mean, using

getItemDropped()

, you can only return 1 kind of item, and not 2 different items.

 

To specify the amount to be dropped using

getDrops(params)

, you need to return an ArrayList containing ItemStacks, in which you can specify the stacksize. If you use something like this:

public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
    ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
    drops.add(new ItemStack(Items.dye, 8, 3));
    return drops;
}

it will drop 8 dyes with a metadata of 3. So with

getDrops(params)

you can be alot more precise then with

getItemDropped()

.

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/

Posted

K thanks for the reply that does seem more useful! I don't have any code for that so I can't send it but I would advice using this method if you need more than 1 type of items to drop though in the case of paprika's you might want only the paprika to drop as the seeds should be simmular to a melon where you can use the crafting table to get them! If you want you can use this code I wrote to test (otherwhise ask the others for further help if needed!):

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
            return customGetDropFunction(p_149650_1_);
    }
    
    private Item itemdropped;
    public Item customGetDropFunction(int p_149650_1_){
            //switch statment for the metadata
    switch (p_149650_1_) {
	    case 5:
                        //sets itemdropped so quantity can be changed latter
	    	 itemdropped = MT_mod.greenpaprika; //Has to be an Item!
                        //sets the item to drop
	      	return itemdropped;
	    case 6:
	    	 itemdropped = MT_mod.greenpaprika;
	    	 return itemdropped;
	    case 7:
	    	 itemdropped = MT_mod.greenpaprika;
	    	 return itemdropped;
	     default:
	    	 itemdropped = MT_mod.PaprikaSeeds;
	    	 return itemdropped;
    }
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    
    public int quantityDropped(Random p_149745_1_)
    {
    	int quant;
        if (itemdropped == MT_mod.PaprikaSeeds){
                //Gives only 1 seed (no dupe glitches that way!)
        	quant = 1;
        }else{
                //Gives min of 1 Paprika and max of 4. Min can be changed by the number before the + the max can be controlled by the number inbetween te () (Which it adds to the number before the + but thats basic math)
        	quant = 1 + p_149745_1_.nextInt(3);
        }
        return quant;
    }

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

Posted

I say you have to override getDrops when you extend BlockCrops. That is because BlockCrops overrides getDrops itself to drop the seeds at a random chance. If you want to change that, you HAVE to override getDrops.

That is true but if you want "true" full control over the block you wouldn't extend BlockCrops now would you?

 

OK maybe that was the No True Scotsman fallacy... (http://en.wikipedia.org/wiki/No_true_Scotsman)

I try not to be mean about your english (as my own isn't the best either) but sometimes I can't help myself!

If you get mad at me for this or any other reason, please look at the profile picture so you'll feel better (and pretier) than me!

Thanks.

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.