Disclaimer: I know that the question is more Java-related than Forge-related.
I know 2 ways to implement wrench like in IC2 (needed to break machine): using interface or using annotation.
I.e. using interface:
interface IWrenchable {}
class MyBlock extends Block implements IWrenchable {}
class WrenchItem extneds Item {
@Override
public EnumActionResult onItemUse(looong args list) {
if (!worldIn.isRemote) {
if (player.isSneaking() && worldIn.getBlockState(pos).getBlock() instanceof IWrenchable) {
worldIn.destroyBlock(pos, true);
player.getHeldItem(hand).damageItem(1, player);
}
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
}
Using annotation:
@Retention(RetentionPolicy.RUNTIME)
@interface Wrenchable {}
@Wrenchable
class MyBlock extends Block {}
class WrenchItem extneds Item {
@Override
public EnumActionResult onItemUse(looong args list) {
if (!worldIn.isRemote) {
if (player.isSneaking() && worldIn.getBlockState(pos).getBlock().getClass().isAnnotationPresent(Wrenchable.class)) {
worldIn.destroyBlock(pos, true);
player.getHeldItem(hand).damageItem(1, player);
}
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
}
Which way is better and faster?