Search in sources :

Example 1 with GlazedTerracottaBlock

use of net.minecraft.block.GlazedTerracottaBlock in project minecolonies by Minecolonies.

the class WorkerUtil method getBestToolForBlock.

/**
 * Get a Tooltype for a certain block. We need this because minecraft has a lot of blocks which have strange or no required tool.
 *
 * @param state         the target BlockState.
 * @param blockHardness the hardness.
 * @return the toolType to use.
 */
public static IToolType getBestToolForBlock(final BlockState state, float blockHardness) {
    final net.minecraftforge.common.ToolType forgeTool = state.getHarvestTool();
    String toolName = "";
    if (forgeTool == null) {
        if (blockHardness > 0f) {
            for (final Tuple<ToolType, ItemStack> tool : getOrInitTestTools()) {
                if (tool.getB() != null && tool.getB().getItem() instanceof ToolItem) {
                    final ToolItem toolItem = (ToolItem) tool.getB().getItem();
                    if (tool.getB().getDestroySpeed(state) >= toolItem.getTier().getSpeed()) {
                        toolName = tool.getA().getName();
                        break;
                    }
                }
            }
        }
    } else {
        toolName = forgeTool.getName();
    }
    final IToolType toolType = ToolType.getToolType(toolName);
    if (toolType == ToolType.NONE && state.getMaterial() == Material.WOOD) {
        return ToolType.AXE;
    } else if (state.getBlock() instanceof GlazedTerracottaBlock) {
        return ToolType.PICKAXE;
    }
    return toolType;
}
Also used : GlazedTerracottaBlock(net.minecraft.block.GlazedTerracottaBlock) IToolType(com.minecolonies.api.util.constant.IToolType) ToolType(com.minecolonies.api.util.constant.ToolType) IToolType(com.minecolonies.api.util.constant.IToolType) ItemStack(net.minecraft.item.ItemStack) ToolItem(net.minecraft.item.ToolItem)

Example 2 with GlazedTerracottaBlock

use of net.minecraft.block.GlazedTerracottaBlock in project minecolonies by ldtteam.

the class WorkerUtil method getBestToolForBlock.

/**
 * Get a Tooltype for a certain block. We need this because minecraft has a lot of blocks which have strange or no required tool.
 *
 * @param state         the target BlockState.
 * @param blockHardness the hardness.
 * @return the toolType to use.
 */
public static IToolType getBestToolForBlock(final BlockState state, float blockHardness) {
    final net.minecraftforge.common.ToolType forgeTool = state.getHarvestTool();
    String toolName = "";
    if (forgeTool == null) {
        if (blockHardness > 0f) {
            for (final Tuple<ToolType, ItemStack> tool : getOrInitTestTools()) {
                if (tool.getB() != null && tool.getB().getItem() instanceof ToolItem) {
                    final ToolItem toolItem = (ToolItem) tool.getB().getItem();
                    if (tool.getB().getDestroySpeed(state) >= toolItem.getTier().getSpeed()) {
                        toolName = tool.getA().getName();
                        break;
                    }
                }
            }
        }
    } else {
        toolName = forgeTool.getName();
    }
    final IToolType toolType = ToolType.getToolType(toolName);
    if (toolType == ToolType.NONE && state.getMaterial() == Material.WOOD) {
        return ToolType.AXE;
    } else if (state.getBlock() instanceof GlazedTerracottaBlock) {
        return ToolType.PICKAXE;
    }
    return toolType;
}
Also used : GlazedTerracottaBlock(net.minecraft.block.GlazedTerracottaBlock) IToolType(com.minecolonies.api.util.constant.IToolType) ToolType(com.minecolonies.api.util.constant.ToolType) IToolType(com.minecolonies.api.util.constant.IToolType) ItemStack(net.minecraft.item.ItemStack) ToolItem(net.minecraft.item.ToolItem)

Aggregations

IToolType (com.minecolonies.api.util.constant.IToolType)2 ToolType (com.minecolonies.api.util.constant.ToolType)2 GlazedTerracottaBlock (net.minecraft.block.GlazedTerracottaBlock)2 ItemStack (net.minecraft.item.ItemStack)2 ToolItem (net.minecraft.item.ToolItem)2