Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
Fix Harvestlevel Override not being able to deal with wildcard oredicts
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Sep 3, 2014
1 parent 0658b85 commit ae47077
Showing 1 changed file with 24 additions and 10 deletions.
Expand Up @@ -15,6 +15,7 @@
import tconstruct.world.blocks.GravelOre;

import java.lang.reflect.Field;
import java.util.LinkedList;

/**
* Used to modify the harvest levels of all known/findable tools and blocks. Vanilla and modded.
Expand Down Expand Up @@ -89,19 +90,32 @@ public static void modifyBlock(ItemStack stack, int harvestLevel)
{
Block block = Block.getBlockFromItem(stack.getItem());

if(Config.logHarvestLevelChanges) {
Log.debug(String.format("Changed Harvest Level of %s from %d to %d", stack.getUnlocalizedName(), block.getHarvestLevel(stack.getItemDamage()), harvestLevel));
}
int meta = stack.getItemDamage();
Integer[] metas;
if(meta == OreDictionary.WILDCARD_VALUE)
metas = new Integer[] {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
else
metas = new Integer[] {meta};

if(Config.logOverrideChanges && Loader.instance().isInState(LoaderState.POSTINITIALIZATION))
Log.info(String.format("Block Override: Changed Harvest Level of %s to %d", stack.getUnlocalizedName(), harvestLevel));
for(int m : metas) {
try {
if (Config.logHarvestLevelChanges) {
Log.debug(String.format("Changed Harvest Level of %s from %d to %d", stack.getUnlocalizedName(), block.getHarvestLevel(m), harvestLevel));
}

// gravelore gets shovel level instead of pickaxe.
if (block instanceof GravelOre)
block.setHarvestLevel("shovel", harvestLevel, m);
else
block.setHarvestLevel("pickaxe", harvestLevel, m);

// gravelore gets shovel level instead of pickaxe.
if(block instanceof GravelOre)
block.setHarvestLevel("shovel", harvestLevel, stack.getItemDamage());
else
block.setHarvestLevel("pickaxe", harvestLevel, stack.getItemDamage());
if (Config.logOverrideChanges && Loader.instance().isInState(LoaderState.POSTINITIALIZATION))
Log.info(String.format("Block Override: Changed Harvest Level of %s to %d", stack.getUnlocalizedName(), harvestLevel));
} catch(Exception e)
{
// exception can occur if stuff does weird things metadatas
}
}
}

private static void modifyTools()
Expand Down

0 comments on commit ae47077

Please sign in to comment.