Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello everyone,

 

I've made a block which has 2 metadata. One is an ore, and one is a brick. When I put this method into my block class, both blocks (metadata 0 and 1), drop the same item. How can I make it, so that, the ore (metadata 0) drops a specific item, and the brick (metadata 1) drops itself (or any other item, it doesn't matter).

 

This is the method that I used in my block class :

 

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

    {

    return MainClass.crystalRainbow;

    }

 

 

Thanks :D

In the method onItemDropped just check if meta == 2 then drop this and if meta == 1 drop this

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

  • Author

In the method onItemDropped just check if meta == 2 then drop this and if meta == 1 drop this

 

Thanks! But, how do I exactly check if metadata is 0 (or 1)?

 

Something like this(?) : public Item getItemDropped(int par1, Random random, int par2)

    {

if(meta == 0){

return MainClass.crystalRainbow;

}

else{

return MainClass.crystalizedDust

}

 

    }

 

 

What do I replace "meta" with ?

 

Sorry I'm a big newbie when It comes to modding, although I know Java a little.

You can make switch case of the 1st int like this :

 

@Override
public Item getItemDropped(int meta, Random random, int int2) {
	Item drop = new Item();
	switch (meta) {
	case 1:
		drop = Items.diamond;
		break;
	case 2:
		drop = Items.apple;
	}
        return drop;
    }

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

  • Author

You can make switch case of the 1st int like this :

 

@Override
public Item getItemDropped(int meta, Random random, int int2) {
	Item drop = new Item();
	switch (meta) {
	case 1:
		drop = Items.diamond;
		break;
	case 2:
		drop = Items.apple;
	}
        return drop;
    }

 

I don't understand this at all. How does it know when to execute case 1 , and when case 2 ?

Learn some basic java - switch case statement

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

  • Author

Learn some basic java - switch case statement

 

I know what switch is and how it works. But, where does it get the metadata of the block that I destroy? "meta" is given as a parameter in the getItemDropped method, but where?

@Override
public Item getItemDropped(int meta, Random random, int int2) {
	Item drop = new Item();
	switch (meta) {
	case 1:
		drop = Items.diamond;
		break;
	case 2:
		drop = Items.apple;
	}
        return drop;
    }

 

(int meta, Random random, int int2)

 

int meta

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

  • Author

@Override
public Item getItemDropped(int meta, Random random, int int2) {
	Item drop = new Item();
	switch (meta) {
	case 1:
		drop = Items.diamond;
		break;
	case 2:
		drop = Items.apple;
	}
        return drop;
    }

 

(int meta, Random random, int int2)

 

int meta

 

Well, I'm a beginner in Java, that's why I didn't understand that, and I still don't understand it completely, but whatever, you helped me. It works!

 

Thanks.

  • Author

@Override
public Item getItemDropped(int meta, Random random, int int2) {
	Item drop = new Item();
	switch (meta) {
	case 1:
		drop = Items.diamond;
		break;
	case 2:
		drop = Items.apple;
	}
        return drop;
    }

 

(int meta, Random random, int int2)

 

int meta

 

I've got one more problem. If I want the block to drop another block, I can't do that because "drop" is the type of an Item, and not a Block.

So for better explanation (sorry for my english) :

basically what switch case is doing -

you will say

 

@Override
public Item getItemDropped(int meta, Random random, int fortune) {
Item drop = new Item(); //drop variable 
switch (meta or any other integer) { //in this case its the integer meta which is basically saying what block you mean
case 1:  //in case the meta int is eqal to 1 
      drop = Items.apple // change the drop variable to apple
      break; //STOP
case 2: //in case the meta is equal to 2
      drop = Items.diamond // change the drop variable to apple
      break;
}
return drop; //now we need to return the item which will be dropped which will be the drop variable

 

for dropping item as block simply :

Item.getItemFromBlock(Blocks.dirt);

 

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

why not  ? :D

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

  • Author

So for better explanation (sorry for my english) :

basically what switch case is doing -

you will say

 

@Override
public Item getItemDropped(int meta, Random random, int fortune) {
Item drop = new Item(); //drop variable 
switch (meta or any other integer) { //in this case its the integer meta which is basically saying what block you mean
case 1:  //in case the meta int is eqal to 1 
      drop = Items.apple // change the drop variable to apple
      break; //STOP
case 2: //in case the meta is equal to 2
      drop = Items.diamond // change the drop variable to apple
      break;
}
return drop; //now we need to return the item which will be dropped which will be the drop variable

 

for dropping item as block simply :

Item.getItemFromBlock(Blocks.dirt);

 

Now I understand it :) . Thanks for the quick explanation! :D

  • Author

What is wrong with new Item(), outside of preInit?

 

Do you know a better method for what I'm trying to do? If so , please tell me :))

ok so Item drop = null; ?

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

  • Author

What ARE you trying to do?

new Item makes a new Item ID (not really, but think of it that way). Every time getDrops is called, you will create a new Item ID. That is not good.

 

Well, read my first post and see what I'm actually trying to do. It's really simple stuff, but I'm a big newbie in modding...

  • Author

 

Seriously... Not because, I can't figure it out, but because no one can give a simple solution and an explanation to my problem.

:D ok so whats worng with

Item drop = null; ?

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Ok so make it like diesieben said :

 

switch (meta) {
    case 0:
        return <>;
    case 1:
        return <>;
    ...
    ...
    default:
        return <default value for unknown meta>;
}

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

What I did in my mod was return null in getItemDropped, and then in the BreakEvent I spawned whatever ItemStack I wanted.

 

EDIT: An easier alternative would be to spawn the itemstack in the breakBlock method

I've also used the getDrops method. And the reason I did that was because when I first started modding I didnt know the proper way to do it.

The proper way IS getDrops, NOT BreakEvent. You would only use BreakEvent if you wanted to modify the behavior of blocks when they are broken, not even to modify drops - there is HarvestDropsEvent specifically for that, and that is still only if you want to modify behavior of blocks that are not your own.

 

For your own blocks, you should never need to use an event to modify anything. Do it all within your Block class.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.