To add xp to a block it's another simple override method with a return value in your modded block class. I also figured out how to get the randomization of the xp drops. If you want your xp randomized see the bottom code.
Here is the unrandomized fixed xp orbes upon drop code:
//HERE IS THE SOLUTION BELOW
@Override
public int getExpDrop(IBlockAccess world, int metadata, int fortune)
{
//THE RETURN VALUE IS HOW MANY XP ORBS IT WILL DROP WHEN THE BLOCK IS BROKEN.
return 2;
}
Here is what it looks like in a block's class file.
package EvilNotch.charcoalblockmod;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class Anthracite_Ore extends Block{
protected Anthracite_Ore (Material Material) {
super(Material);
this.setHardness(4.0F);
this.setResistance(5.7F);
this.setStepSound(soundTypePiston);
this.setHarvestLevel("picaxe", 2);
}
//changes the blocks value from itself to an item
@Override
public Item getItemDropped(int metadata, Random rand, int fortune) {
return charcoalblockmod.Anthracite_Coal;
}
//HERE IS THE SOLUTION BELOW
@Override
public int getExpDrop(IBlockAccess world, int metadata, int fortune)
{
//THE RETURN VALUE IS HOW MANY XP ORBS IT WILL DROP WHEN THE BLOCK IS BROKEN.
return 2;
}
}
Random xp drops. you will have to import random java util and math helper in order for the fallowing code to work. This line of code again goes into your block class.
private Random rand = new Random();
@Override
public int getExpDrop(IBlockAccess p_149690_1_, int p_149690_5_, int p_149690_7_)
{
if (this.getItemDropped(p_149690_5_, rand, p_149690_7_) != Item.getItemFromBlock(this))
{
int j1 = 0;
//This is your mod and then the block
if (this == charcoalblockmod.Anthracite_Ore)
{
//the 0 is minimum xp and the 2 is the max xp orbs it can drop
j1 = MathHelper.getRandomIntegerInRange(rand, 0, 2);
}
return j1;
}
return 0;
}
If you look at BlockOre (the class used by ore blocks), you'll see that it overrides Block#getExpDrop to control how much experience is dropped when it's mined. You'll also see that its override of this method returns a random amount based on the type of ore it is.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I don't understand what the vanilla ores are doing to replicate it with forge so that they would be the same. I however did see it override the method to make xp drops random. I don't however know what methods to use to get it to only harvest it on a pickaxe.
I don't know what methods to use for creating random xp. I looked at the class atempted to override it and nothing happned. I could try agian but, I am not quite what java method to use for the class . public I know needs to be there. static shouldn't everything be static by definition I don't get it? void methods have no return values. I don't even know for random. I tried making an if statement and that didn't work
@Override
public int onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta){
this.dropXpOnBlockBreak(world, x , y, z,);
if this.dropXpOnBlockBreak(world, x , y, z,) return 0 + rand.nextInt(2);
}
All you need to do is override Block#getExpDrop to return the amount of XP to drop, Minecraft will automatically drop this amount when the block is broken by a player that's not in creative mode.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
You can answer the question for yourself by looking at the source of the Block class and scrolling down to the getExpDrop method or just using your IDE to auto-generate an override for it in your Anthracite_Ore class.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks I don't feel helpless anymore but, I still might need you if I get stuck for randomization do you create an xp handler overriding the statement I just made or what's the deal with that? vanilla has the code in 2 different places one looks like it handles it and the other states it. My friend looked for 3 hours and gave up you are very good thanks alot. I also don't get what the obfuscated code is for in mcp? do I look it up and find the function ?
Thanks I don't feel helpless anymore but, I still might need you if I get stuck for randomization do you create an xp handler overriding the statement I just made or what's the deal with that? vanilla has the code in 2 different places one looks like it handles it and the other states it. My friend looked for 3 hours and gave up you are very good thanks alot. I also don't get what the obfuscated code is for in mcp? do I look it up and find the function ?
I'm not really sure what you're talking about, sorry. Block#getExpDrop is the only method that controls how much experience your block drops when mined. There's no XP handler system (though dropped XP can be modified with BlockEvent.BreakEvent).
I'm not entirely sure which obfuscated code you're talking about, either. There are three sets of names in the MCP system:
Notch names like aa or ab. These are created by the obfuscation process Mojang uses and change with each version of Minecraft. The non-development client and server JARs use these names.
SRG/Searge names like Block, func_0010_a and field_0021_b. The MCP team manually deobfuscate class names and then assign each field/method an auto-generated globally unique name that remains stable across Minecraft versions. FML deobfuscates to these names at runtime and Forge mods are compiled to use these names.
MCP names like Block, setLightValue and blockResistance. The community contributes the MCP name for each SRG name via MCPBot and thus these can change with each mappings version. The development client and server use these names.
MCP provides mapping files that can be used to convert between each set of names. In particular, the CSV files downloadable from the MCPBot website map convert between SRG and MCP names.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
well I don't get what is going on on the randomization of xp could you please tell me the code to make it randomized. I am working on a mod called technicoal and they need to have random xp. currently there is over 700 lines of code that I am developing as we speak. It's going to be the ultimate coal mod. there is going to even be ender coal spawning in the end. here is the current code
@Override
public int getExpDrop(IBlockAccess world, int metadata, int fortune)
{
//THE RETURN VALUE IS HOW MANY XP ORBS IT WILL DROP WHEN THE BLOCK IS BROKEN.
return 2;
}
Here is vanilla ore class code . Is there a way to make it like vanilla and just put all of this in one class then refer to it in the actual block class with minimal lines of code. I currently just copied the code into the actual block class and the randomization works but, I would like it in one class and I have tried doing it before but, it didn't seem to work. Thank you
private Random rand = new Random();
@Override
public int getExpDrop(IBlockAccess p_149690_1_, int p_149690_5_, int p_149690_7_)
{
if (this.getItemDropped(p_149690_5_, rand, p_149690_7_) != Item.getItemFromBlock(this))
{
int j1 = 0;
if (this == Blocks.coal_ore)
{
j1 = MathHelper.getRandomIntegerInRange(rand, 0, 2);
}
else if (this == Blocks.diamond_ore)
{
j1 = MathHelper.getRandomIntegerInRange(rand, 3, 7);
}
else if (this == Blocks.emerald_ore)
{
j1 = MathHelper.getRandomIntegerInRange(rand, 3, 7);
}
else if (this == Blocks.lapis_ore)
{
j1 = MathHelper.getRandomIntegerInRange(rand, 2, 5);
}
else if (this == Blocks.quartz_ore)
{
j1 = MathHelper.getRandomIntegerInRange(rand, 2, 5);
}
return j1;
}
return 0;
}
Vanilla uses the same class for multiple ores, so it checks which ore the current block is before deciding how much XP to drop. If you're using the same class for multiple ores, I suggest you create fields for the minimum and maximum XP and use those as the bounds for MathHelper.getRandomIntegerInRange in getExpDrop.
If you're using each class for one ore only, just call MathHelper.getRandomIntegerInRange with the minimum and maximum XP directly.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I don't know how to make multiple blocks in one class. Could you send me a tutorial link? I would also like to know how to get a more advanced setup for a more complex mod so it would work with servers. hopefully my mod still should work on a server because, I havn't rendered anything new. Could you also send me a good tutorial for that. I was looking at the divinerpg source code and I don't know what they are doing but, all of their public statics were in one class. I would like something like they did for my advanced mod setup.
To use one Block instance for multiple blocks, you need metadata (1.7.10) or blockstates (1.8.x). The basic idea is that most methods will provide you with the metadata of the current block, you can use this to determine what the method does (e.g. return a different icon or a different unlocalised name).
To use one Block class for multiple blocks, allow the block's properties to be configured via the constructor or setter methods instead of hardcoding them.
To make your mod work with servers, just avoid using client-only classes outside of client-only code. You may also want to read up on networking.
I don't know of many good tutorials, all I can suggest is searching for them yourself and looking at the Minecraft code.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Additional Credits: Choonster
To add xp to a block it's another simple override method with a return value in your modded block class. I also figured out how to get the randomization of the xp drops. If you want your xp randomized see the bottom code.
Here is the unrandomized fixed xp orbes upon drop code:
Here is what it looks like in a block's class file.
Random xp drops. you will have to import random java util and math helper in order for the fallowing code to work. This line of code again goes into your block class.
If you look at BlockOre (the class used by ore blocks), you'll see that it overrides Block#getExpDrop to control how much experience is dropped when it's mined. You'll also see that its override of this method returns a random amount based on the type of ore it is.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
my main concern was that
if you punched the block in creative = xp
if you have silk touch pick and use it = xp
I don't understand what the vanilla ores are doing to replicate it with forge so that they would be the same. I however did see it override the method to make xp drops random. I don't however know what methods to use to get it to only harvest it on a pickaxe.
I don't know what methods to use for creating random xp. I looked at the class atempted to override it and nothing happned. I could try agian but, I am not quite what java method to use for the class . public I know needs to be there. static shouldn't everything be static by definition I don't get it? void methods have no return values. I don't even know for random. I tried making an if statement and that didn't work
All you need to do is override Block#getExpDrop to return the amount of XP to drop, Minecraft will automatically drop this amount when the block is broken by a player that's not in creative mode.
You don't need to drop the XP yourself.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
do you need parameters and what would they look like?
I tried this and it said to remove the override
You can answer the question for yourself by looking at the source of the Block class and scrolling down to the getExpDrop method or just using your IDE to auto-generate an override for it in your Anthracite_Ore class.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks I don't feel helpless anymore but, I still might need you if I get stuck for randomization do you create an xp handler overriding the statement I just made or what's the deal with that? vanilla has the code in 2 different places one looks like it handles it and the other states it. My friend looked for 3 hours and gave up you are very good thanks alot. I also don't get what the obfuscated code is for in mcp? do I look it up and find the function ?
I am noob I misspelled pickaxe sorry about that.
I'm not really sure what you're talking about, sorry. Block#getExpDrop is the only method that controls how much experience your block drops when mined. There's no XP handler system (though dropped XP can be modified with BlockEvent.BreakEvent).
I'm not entirely sure which obfuscated code you're talking about, either. There are three sets of names in the MCP system:
MCP provides mapping files that can be used to convert between each set of names. In particular, the CSV files downloadable from the MCPBot website map convert between SRG and MCP names.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
well I don't get what is going on on the randomization of xp could you please tell me the code to make it randomized. I am working on a mod called technicoal and they need to have random xp. currently there is over 700 lines of code that I am developing as we speak. It's going to be the ultimate coal mod. there is going to even be ender coal spawning in the end. here is the current code
Here is vanilla ore class code . Is there a way to make it like vanilla and just put all of this in one class then refer to it in the actual block class with minimal lines of code. I currently just copied the code into the actual block class and the randomization works but, I would like it in one class and I have tried doing it before but, it didn't seem to work. Thank you
Vanilla uses the same class for multiple ores, so it checks which ore the current block is before deciding how much XP to drop. If you're using the same class for multiple ores, I suggest you create fields for the minimum and maximum XP and use those as the bounds for MathHelper.getRandomIntegerInRange in getExpDrop.
If you're using each class for one ore only, just call MathHelper.getRandomIntegerInRange with the minimum and maximum XP directly.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I don't know how to make multiple blocks in one class. Could you send me a tutorial link? I would also like to know how to get a more advanced setup for a more complex mod so it would work with servers. hopefully my mod still should work on a server because, I havn't rendered anything new. Could you also send me a good tutorial for that. I was looking at the divinerpg source code and I don't know what they are doing but, all of their public statics were in one class. I would like something like they did for my advanced mod setup.
To use one Block instance for multiple blocks, you need metadata (1.7.10) or blockstates (1.8.x). The basic idea is that most methods will provide you with the metadata of the current block, you can use this to determine what the method does (e.g. return a different icon or a different unlocalised name).
To use one Block class for multiple blocks, allow the block's properties to be configured via the constructor or setter methods instead of hardcoding them.
To make your mod work with servers, just avoid using client-only classes outside of client-only code. You may also want to read up on networking.
I don't know of many good tutorials, all I can suggest is searching for them yourself and looking at the Minecraft code.
Make sure you have a solid understanding of Java.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.