Java源码示例:net.minecraft.item.ItemHoe

示例1
static boolean makeFarmland(World world, BlockPos pos, IBetterChest chest, boolean simulate) {
	BlockPos below = pos.down();
	IBlockState blockBelow = world.getBlockState(below);
	boolean farmland = false;
	if (blockBelow.getBlock() == Blocks.DIRT || blockBelow.getBlock() == Blocks.GRASS) {
		int hoe = InvUtil.findInInvInternal(chest, null, test -> test.getItem() instanceof ItemHoe);
		if (hoe != -1) {
			farmland = true;
			if (!simulate) {
				ItemStack tool = chest.getStackInSlot(hoe);
				tool.attemptDamageItem(1, world.rand, null);
				if (tool.getItemDamage() > tool.getMaxDamage()) {
					tool.setItemDamage(0);
					tool.setCount(tool.getCount() - 1);
				}

				world.setBlockState(below, Blocks.FARMLAND.getDefaultState());
			}
		}
	}

	return farmland;
}
 
示例2
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
    if (!worldIn.isRemote && stack.getItem() instanceof ItemHoe) {
        super.harvestBlock(worldIn,player,pos,state,te,stack);
    }
}
 
示例3
/**
 * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't fuel
 * @param stack
 * @return
 */
private static int getItemBurnTime(ItemStack stack)
{
    if (stack.isEmpty())
    {
        return 0;
    }

    int burnTime = ForgeEventFactory.getItemBurnTime(stack) * COOKTIME_DEFAULT * 3 / 400;

    if (burnTime >= 0)
    {
        return burnTime;
    }

    Item item = stack.getItem();

    if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR)
    {
        Block block = Block.getBlockFromItem(item);
        if (block.getDefaultState().getMaterial() == Material.WOOD) { return COOKTIME_DEFAULT * 225 / 100; }
        if (block == Blocks.COAL_BLOCK) { return COOKTIME_DEFAULT * 120; }
        if (block == Blocks.WOODEN_SLAB) { return COOKTIME_DEFAULT * 45 / 40; }
        if (block == Blocks.SAPLING) return COOKTIME_DEFAULT * 3 / 4;
    }
    else
    {
        if (item == Items.COAL) return COOKTIME_DEFAULT * 12;
        if (item == Items.BLAZE_ROD) return COOKTIME_DEFAULT * 18;

        if (item == Items.LAVA_BUCKET) return COOKTIME_DEFAULT * 150;
        if (item == Items.STICK) return COOKTIME_DEFAULT * 3 / 4;
        if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;
        if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;
        if (item instanceof ItemHoe && ((ItemHoe)item).getMaterialName().equals("WOOD")) return COOKTIME_DEFAULT * 15 / 10;

        // Ender Furnace custom fuels
        if (item == Items.BLAZE_POWDER) return COOKTIME_DEFAULT * 9;
        if (item == Items.ENDER_PEARL) { return COOKTIME_DEFAULT * 8; }
        if (item == Items.ENDER_EYE) { return COOKTIME_DEFAULT * 17; }
    }

    return 0;
}