Java MC coding: Ore drops block not item

Sykos

New Member
In a mod for minecraft I am making, I have an ore that I want to make mineable with only iron+ tier pickaxes. Right now, it does not matter what tool is used and it drops the ore itself. The code that's commented out will make it drop the item but not require a specific tool.

Code:
package net.minecraft.src;

import java.util.Random;

public class BlockDemoniteOre extends Block
{	
	
        protected BlockDemoniteOre(int i, int j)
        {
                super(i, j, Material.iron);
                this.setCreativeTab(CreativeTabs.tabBlock);
        }
        public int idDropped(int i, Random random, int par3, EntityPlayer entityplayer)
        {
                 if (entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.pickaxeSteel.itemID)
                 {
                  return mod_DeathShard.dshard.itemID;
                 }
                 if (entityplayer.getCurrentEquippedItem() !=  null && entityplayer.getCurrentEquippedItem().itemID == Item.pickaxeDiamond.itemID)
                 {
                  return mod_DeathShard.dshard.itemID;
                 }
                 else
                 {
                  return 0;
                 }

        }
       /* public int idDropped(int i, Random random, int par3)
    	{
    		return mod_DeathShard.dshard.itemID;
    	}*/
        public int quantityDropped(Random random)
    	{
    		return 1;
    	}
}
 
1, wrong section common mistake but don't worry lol.

also, you need to make the ore mineable with only the item you want or better.

so for instance in a theory simple way, the way I make it logical really (this is not a language that can be used for anything):
Code:
if (pickAxeID = 2) //Lets say 2 is Iron
{
    //Logic for the ore to drop
}
else if (pickAxeID = 3)//lets say 3 is Something better
{
    //Logic for ore to drop
}
else if (pickAxeID = 4) //lets say 4 is diamond
{
//same logic
}
else
{
//no drop 
}

Its just a way to make it more logical for me, so I'm not sure if it helps but its a good idea to keep it in mind.
 
It does help some, actually. Only problem is, I know how to mod, but not code, per say. This is my first experience with java, and I know a little of the format and the extreme basics of java. I don't actually know to physically type into the code XP. Also, what sub-forum should this be posted in (for future reference)?
 
Last edited:
(another transition word here), this code drops the item I want, so I think it has something to do with "Entityplayer entityplayer".
Code:
package net.minecraft.src;

import java.util.Random;

public class BlockDemoniteOre extends Block
{	
	
        protected BlockDemoniteOre(int i, int j)
        {
                super(i, j, Material.iron);
                this.setCreativeTab(CreativeTabs.tabBlock);
        }
        public int idDropped(int i, Random random, int par3)
        {
                 /*if (entityplayer.getCurrentEquippedItem().itemID == Item.pickaxeSteel.itemID)
                 {
                  return mod_DeathShard.dshard.itemID;
                 }
                 else if (entityplayer.getCurrentEquippedItem() !=  null && entityplayer.getCurrentEquippedItem().itemID == Item.pickaxeDiamond.itemID)
                 {
                  return mod_DeathShard.dshard.itemID;
                 }
                 else
                 {
                  return 0;
                 }*/
        		return mod_DeathShard.dshard.itemID;

        }
       /* public int idDropped(int i, Random random, int par3)
    	{
    		return mod_DeathShard.dshard.itemID;
    	}*/
        public int quantityDropped(Random random)
    	{
    		return 1;
    	}
}
 
1, wrong section common mistake but don't worry lol.

also, you need to make the ore mineable with only the item you want or better.

so for instance in a theory simple way, the way I make it logical really (this is not a language that can be used for anything):
Code:
if (pickAxeID = 2) //Lets say 2 is Iron
{
    //Logic for the ore to drop
}
else if (pickAxeID = 3)//lets say 3 is Something better
{
    //Logic for ore to drop
}
else if (pickAxeID = 4) //lets say 4 is diamond
{
//same logic
}
else
{
//no drop 
}

Its just a way to make it more logical for me, so I'm not sure if it helps but its a good idea to keep it in mind.

I don't know Java at all but I do program. Wouldn't it make more sense to do if it's greater than or equal to 2 rather than separate ifs for all of the different kinds of picks.
 
I don't think we actually know what the IDs are for the pickaxes so that might not work.
(I know java some java, but not enough to solve this problem lol)
 
Iron is 258, diamond is 278. I tried using the id's, and no errors occurred but no shards were dropped either.
 
I don't know Java at all but I do program. Wouldn't it make more sense to do if it's greater than or equal to 2 rather than separate ifs for all of the different kinds of picks.

Yeah but remember, it was an example to simplify the coding process. if this is a way to make the code, then from there on you can advancee it and make it shorter etc.

Iron is 258, diamond is 278. I tried using the id's, and no errors occurred but no shards were dropped either.

there is a way in a switch case to make it easier:

Code:
switch ()
{
   case 1: <ID Of Pick>
               logic
               return block or whatever its declared as;
               break;
    case 2: <ID Of Pick>
               logic
               return block or whatever its declared as;
               break;
    default: break;
}

just first do some searches on loops and logic of dropping an item etc. I'll look for a test source of a pirvate server i coded and find some examples, it is c# but the idea is the same
 
Last edited:
*Raises hand* I know Java! Though, I have no idea what your issue is. If you are still having problems, create a new post that details it.
 
*Raises hand* I know Java! Though, I have no idea what your issue is. If you are still having problems, create a new post that details it.

basically he has a custom ore and wants to mine it with a certain pickaxe or higher. Thats what I've gathered
 
Back
Top