This nifty class will allow you to modify harvesting lists of various ItemTools: pickaxes, axes and shovels. It provides two static methods which you may call from your own mod:
where "Harvester" is a basic interface through which you can provide an answer to the question if a tool can harvest some block, or not.
But I think it's much easier to understand by looking at examples. Here are the ones from the marble mod:
public static final np lightMarble;
public static final np darkMarble;
public static final np specialMarble;
public mod_Marble() { // the constructor
ToolUtils.registerBlocks(ToolUtils.Type.PICKAXE, lightMarble, darkMarble, specialMarble);
ToolUtils.registerHarvester(ToolUtils.Type.PICKAXE, new marbleHarvester());
}
static {
// .setHardness .setResistance .setStepSound + stone sound var
lightMarble = (new marbleBlock(marbleBlock.lightMarbleId, 132)).c(3.0F).b(15F).a(np.h);
darkMarble = (new marbleBlock(marbleBlock.darkMarbleId, 136)).c(3.0F).b(15F).a(np.h);
specialMarble = (new marbleBlock(marbleBlock.specialMarbleId, 140)).c(3.0F).b(15F).a(np.h);
}
Here you can see how marble blocks are constructed and used in registerBlocks method, so that pickaxes will break less when applied vs. marble blocks. As for marbleHarvester class, here it goes:
public class marbleHarvester implements ToolUtils.Harvester {
public ToolUtils.HarvesterAnswer canHarvestBlock(np block, int toolQuality) {
// block.bh is block.blockID
if (block.bh == marbleBlock.darkMarbleId ||
block.bh == marbleBlock.lightMarbleId ||
block.bh == marbleBlock.specialMarbleId)
return toolQuality >= 2 ? ToolUtils.HarvesterAnswer.TRUE : ToolUtils.HarvesterAnswer.FALSE;
return ToolUtils.HarvesterAnswer.DONT_KNOW;
}
}
As you can see, it checks if the current block is one of them marbles and then returns a definitive "true" if toolQuality >= 2 (i.e. iron tools or better), and definitive "false" if quality is lower. But if the current block isn't marble, then it returns DONT_KNOW, so that some other code (other mods or vanilla Minecraft) can decide what to do with other blocks.
So, why would you want to use it?
Mostly because it makes tool-adjusting mods compatible. Several mods can register their custom block harvesters, and they ALL will work well together! Just remember to return correct answer (DONT_KNOW if you don't want to mess with some block) in canHarvestBlock method so that other mods can apply their rules too.
Links / b1.2: (NOTE: there was some structural changes in this version, see the source code for details)
1) Compiled ToolUtils;
2) Sources.
Kudos to you. This seems very nice, and very useful. One question though, the tool quality of the weapon. Are the numbers 0, 1, 2 and 5 for gold/wood, stone, iron and diamond? I think I remember seeing that in the code somewhere.
There's no such setting as the "mining speed". It calculates itself from several factors, like:
- tool quality;
- item "hardness" factor;
- if .canHarvestBlock() reports true, then it speeds up the process quite a lot.
I guess your changes is about your Emerald mod? How much hardness have your ore blocks? Are you sure that you're correctly reporting them as "harvestable"?
Gee, it turned out that there were more bugs around axes and shovels (pickaxes were working fine) and .registerBlocks(). Squashed them all, and actually tested everything on MC. Things are really fine now.
I've also improved logic a little (no changes for the end user), so it messes with vanilla Minecraft a bit less now if it is not needed.
But you can decompile other mods for blockIDs, and add them to your tool, no?
Hm, I looked through the code, and can't quite understand why you can't subclass Custom<etc> class of ToolUtils and add your own code. It's designed to work quite fine, just don't touch the .a(og block) method (or at least, always do super.a() call if you override it), as it's the key to all the integration.
PS: Anyways, I think you should just discuss it in #risucraft, see if we can figure out the problem.
Hrm...I want to use this, but I really don't understand how. I basically want to turn my RealisticAxe mod into a ModLoader/ToolUtils mod, so that it doesn't rely on editing the ItemAxe class directly.
If you don't want to look at my mod, all it does is simply add more things to the list that axes are good for (stairs, workbenches, jukeboxes, etc.).
Well I guess my question would be if I really need the harvest one for adding blocks to the axe's effective list. I'm not quite sure, but it looks to me like it would only require the register block method because axes can already harvest everything I'm adding...right?
I don't know, I suppose I just can't figure out what exactly each method does.
Well I guess my question would be if I really need the harvest one for adding blocks to the axe's effective list. I'm not quite sure, but it looks to me like it would only require the register block method because axes can already harvest everything I'm adding...right?
If you won't change their material, you shouldn't need to use the harvester. I think.
I had to change the material of my Darkwood, so it can't be chopped down without min. Iron Axe.
Alright, I think I understand. I'll try it out tonight when I get the chance. Thanks. :smile.gif:
Oh, and how difficult would it be to add other/custom tools to the list? Say I want to add that hoes can harvest some of my new blocks, but I don't want to edit the hoe's class? Or maybe someone will want to use my (was originally Shockah's) shears to harvest something else?
Speaking of shears Shockah, you're gonna like what I did with them. :smile.gif:
What would be really nice is if I could find a way to make the recent Diamond paxel compatible with all other mods, as of right now, it won't react to extras properly. So how would I go about doing this, then? It counts as a pickaxe, axe, and shovel in one... and does magnificent damage to mobs too.
where "Type" is one of the ToolUtils.Type.PICKAXE, ToolUtils.Type.AXE or ToolUtils.Type.SHOVEL
and
where "Harvester" is a basic interface through which you can provide an answer to the question if a tool can harvest some block, or not.
But I think it's much easier to understand by looking at examples. Here are the ones from the marble mod:
Here you can see how marble blocks are constructed and used in registerBlocks method, so that pickaxes will break less when applied vs. marble blocks. As for marbleHarvester class, here it goes:
As you can see, it checks if the current block is one of them marbles and then returns a definitive "true" if toolQuality >= 2 (i.e. iron tools or better), and definitive "false" if quality is lower. But if the current block isn't marble, then it returns DONT_KNOW, so that some other code (other mods or vanilla Minecraft) can decide what to do with other blocks.
So, why would you want to use it?
Mostly because it makes tool-adjusting mods compatible. Several mods can register their custom block harvesters, and they ALL will work well together! Just remember to return correct answer (DONT_KNOW if you don't want to mess with some block) in canHarvestBlock method so that other mods can apply their rules too.
Links / b1.2: (NOTE: there was some structural changes in this version, see the source code for details)
1) Compiled ToolUtils;
2) Sources.
Old Links / b1.1_02:
1) Compiled ToolUtils;
2) Sources.
Old Links / b1.0_01:
1) Compiled ToolUtils;
2) Sources.
- tool quality;
- item "hardness" factor;
- if .canHarvestBlock() reports true, then it speeds up the process quite a lot.
I guess your changes is about your Emerald mod? How much hardness have your ore blocks? Are you sure that you're correctly reporting them as "harvestable"?
I've updated files, please re-download them.
I've also improved logic a little (no changes for the end user), so it messes with vanilla Minecraft a bit less now if it is not needed.
Anyone who cares should redownload files.
Hm, I looked through the code, and can't quite understand why you can't subclass Custom<etc> class of ToolUtils and add your own code. It's designed to work quite fine, just don't touch the .a(og block) method (or at least, always do super.a() call if you override it), as it's the key to all the integration.
PS: Anyways, I think you should just discuss it in #risucraft, see if we can figure out the problem.
2 things.
How do I set this up for the Mineral mod?
How do I open class files to edit them?
I tried that.
You see, I've installed Dyes, and Minerals. I installed this in such a way, and deleted META-INF.
It doesn't work, I still get the black MOJANG SPECIFICATIONS screen...
If you don't want to look at my mod, all it does is simply add more things to the list that axes are good for (stairs, workbenches, jukeboxes, etc.).
https://modrinth.com/user/Roundaround
I don't know, I suppose I just can't figure out what exactly each method does.
https://modrinth.com/user/Roundaround
Alright, I think I understand. I'll try it out tonight when I get the chance. Thanks. :smile.gif:
Oh, and how difficult would it be to add other/custom tools to the list? Say I want to add that hoes can harvest some of my new blocks, but I don't want to edit the hoe's class? Or maybe someone will want to use my (was originally Shockah's) shears to harvest something else?
Speaking of shears Shockah, you're gonna like what I did with them. :smile.gif:
https://modrinth.com/user/Roundaround