Feed The Beast Wiki

Follow the Feed The Beast Wiki on Discord or Mastodon!

READ MORE

Feed The Beast Wiki
Advertisement
ToolUtils
Current developersjust_dont_do_it, Shockah
Supported Minecraft versionsB1.2_01, B1.3_01
URLLink

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:

CODE: SELECT ALL
ToolUtils.registerBlocks(Type type, np... blockList)


where "Type" is one of the ToolUtils.Type.PICKAXE, ToolUtils.Type.AXE or ToolUtils.Type.SHOVEL


and

CODE: SELECT ALL
ToolUtils.registerHarvester(Type t, ToolUtils.Harvester harvester)


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:

CODE: SELECT ALL
  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:

CODE: SELECT ALL
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.

To modders:

Code

void ToolUtils.Pickaxe.addBlocks(az toolClass, qk... blocks) - adds mineable blocks for that tool class

void ToolUtils.Pickaxe.addBlocksMinimum(az toolClass, qk... blocks) - adds mineable blocks for that + better tool classes

void ToolUtils.Pickaxe.addBlocksTool(ex tool qk... blocks) - adds mineable blocks for that tool

ToolUtils.Shovel.(...)

ToolUtils.Axe.(...)


int ToolUtils.wrapToolClass(az toolClass) - returns tool class number

az ToolUtils.wrapToolClass(int toolClass) - returns tool class

int ToolUtils.getClassQuality(az toolClass) - returns tool quality (almost the same as wrapToolClass, but returns 0 for gold)

Advertisement