Add fallback item constant to ToolSet

This commit is contained in:
Brady 2018-08-06 19:43:20 -05:00
parent 24cbb5e149
commit 1beff941d2
No known key found for this signature in database
GPG Key ID: 73A788379A197567
1 changed files with 5 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAir;
import net.minecraft.item.ItemStack;
@ -23,6 +24,8 @@ import java.util.Map;
*/
public class ToolSet {
private static final Item FALLBACK_ITEM = Items.APPLE;
/**
* A list of tools on the hotbar that should be considered.
* Note that if there are no tools on the hotbar this list will still have one (null) entry.
@ -83,7 +86,7 @@ public class ToolSet {
for (byte i = 0; i < tools.size(); i++) {
Item item = tools.get(i);
if (item == null) {
item = Item.getByNameOrId("minecraft:apple");
item = FALLBACK_ITEM;
}
float v = item.getDestroySpeed(new ItemStack(item), b);
if (v < value || value == -1) {
@ -118,7 +121,7 @@ public class ToolSet {
public double getStrVsBlock(IBlockState b, BlockPos pos) {
Item item = this.getBestTool(b);
if (item == null) {
item = Item.getByNameOrId("minecraft:apple");
item = FALLBACK_ITEM;
}
float f = b.getBlockHardness(Minecraft.getMinecraft().world, pos);
return f < 0.0F ? 0.0F : (!canHarvest(b, item) ? item.getDestroySpeed(new ItemStack(item), b) / f / 100.0F : item.getDestroySpeed(new ItemStack(item), b) / f / 30.0F);